diff --git a/components/squeezelite-ota/squeezelite-ota.c b/components/squeezelite-ota/squeezelite-ota.c index 2b1ee964..6d393753 100644 --- a/components/squeezelite-ota/squeezelite-ota.c +++ b/components/squeezelite-ota/squeezelite-ota.c @@ -44,7 +44,7 @@ uint8_t newpct=0; static esp_http_client_config_t config; static esp_http_client_config_t ota_config; static esp_http_client_handle_t client; - +extern void wifi_manager_refresh_ota_json(); const char * ota_get_status(){ if(!ota_status.bInitialized) { @@ -93,10 +93,12 @@ esp_err_t _http_event_handler(esp_http_client_event_t *evt) case HTTP_EVENT_ON_CONNECTED: ESP_LOGD(TAG, "HTTP_EVENT_ON_CONNECTED"); if(ota_status.bOTAStarted) snprintf(ota_status.status_text,sizeof(ota_status.status_text)-1,"Installing..."); + wifi_manager_refresh_ota_json(); ota_status.ota_total_len=0; ota_status.ota_actual_len=0; lastpct=0; newpct=0; + wifi_manager_refresh_ota_json(); ESP_LOGD(TAG,"Heap internal:%zu (min:%zu) external:%zu (min:%zu)\n", heap_caps_get_free_size(MALLOC_CAP_INTERNAL), heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL), @@ -128,6 +130,7 @@ esp_err_t _http_event_handler(esp_http_client_event_t *evt) if(ota_get_pct_complete()%5 == 0) newpct = ota_get_pct_complete(); if(lastpct!=newpct ) { + wifi_manager_refresh_ota_json(); lastpct=newpct; ESP_LOGD(TAG,"Receiving OTA data chunk len: %d, %d of %d (%d pct)", evt->data_len, ota_status.ota_actual_len, ota_status.ota_total_len, newpct); ESP_LOGD(TAG,"Heap internal:%zu (min:%zu) external:%zu (min:%zu)\n", @@ -196,6 +199,7 @@ void ota_task(void *pvParameter) ota_status.bInitialized = true; ESP_LOGD(TAG, "HTTP ota Thread started"); snprintf(ota_status.status_text,sizeof(ota_status.status_text)-1,"Initializing..."); + wifi_manager_refresh_ota_json(); ota_status.bRedirectFound=false; if(passedURL==NULL || strlen(passedURL)==0){ ESP_LOGE(TAG,"HTTP OTA called without a url"); @@ -208,6 +212,7 @@ void ota_task(void *pvParameter) FREE_RESET(pvParameter); snprintf(ota_status.status_text,sizeof(ota_status.status_text)-1,"Checking for redirect..."); + wifi_manager_refresh_ota_json(); check_http_redirect(); if(ota_status.bRedirectFound && ota_status.redirected_url== NULL){ // OTA Failed miserably. Errors would have been logged somewhere @@ -218,14 +223,17 @@ void ota_task(void *pvParameter) init_config(&ota_config,ota_status.bRedirectFound?ota_status.redirected_url:ota_status.current_url); ota_status.bOTAStarted = true; snprintf(ota_status.status_text,sizeof(ota_status.status_text)-1,"Starting OTA..."); + wifi_manager_refresh_ota_json(); // pause to let the system catch up vTaskDelay(1500/ portTICK_RATE_MS); esp_err_t err = esp_https_ota(&config); if (err == ESP_OK) { snprintf(ota_status.status_text,sizeof(ota_status.status_text)-1,"Success!"); + wifi_manager_refresh_ota_json(); esp_restart(); } else { snprintf(ota_status.status_text,sizeof(ota_status.status_text)-1,"Error: %s",esp_err_to_name(err)); + wifi_manager_refresh_ota_json(); ESP_LOGE(TAG, "Firmware upgrade failed with error : %s", esp_err_to_name(err)); } FREE_RESET(ota_status.current_url); diff --git a/components/wifi-manager/wifi_manager.c b/components/wifi-manager/wifi_manager.c index 4be69d6e..b76772e4 100644 --- a/components/wifi-manager/wifi_manager.c +++ b/components/wifi-manager/wifi_manager.c @@ -129,7 +129,9 @@ const int WIFI_MANAGER_SCAN_BIT = BIT7; const int WIFI_MANAGER_REQUEST_DISCONNECT_BIT = BIT8; - +void wifi_manager_refresh_ota_json(){ + wifi_manager_send_message(EVENT_REFRESH_OTA, NULL); +} void wifi_manager_scan_async(){ wifi_manager_send_message(ORDER_START_WIFI_SCAN, NULL); @@ -1131,9 +1133,15 @@ void wifi_manager( void * pvParameters ){ /* callback */ if(cb_ptr_arr[msg.code]) (*cb_ptr_arr[msg.code])(NULL); - break; - + case UPDATE_CONNECTION_OK: + /* refresh JSON with the new ota data */ + if(wifi_manager_lock_json_buffer( portMAX_DELAY )){ + /* generate the connection info with success */ + wifi_manager_generate_ip_info_json( UPDATE_CONNECTION_OK ); + wifi_manager_unlock_json_buffer(); + } + break; case ORDER_DISCONNECT_STA: ESP_LOGI(TAG, "MESSAGE: ORDER_DISCONNECT_STA"); diff --git a/components/wifi-manager/wifi_manager.h b/components/wifi-manager/wifi_manager.h index aa89de07..cb534015 100644 --- a/components/wifi-manager/wifi_manager.h +++ b/components/wifi-manager/wifi_manager.h @@ -212,7 +212,8 @@ typedef enum message_code_t { EVENT_STA_DISCONNECTED = 12, EVENT_SCAN_DONE = 13, EVENT_STA_GOT_IP = 14, - MESSAGE_CODE_COUNT = 15 /* important for the callback array */ + EVENT_REFRESH_OTA = 15, + MESSAGE_CODE_COUNT = 16 /* important for the callback array */ }message_code_t;