mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-09 13:07:03 +03:00
More OTA changes, new build target
This commit is contained in:
@@ -98,12 +98,11 @@ esp_err_t _http_event_handler(esp_http_client_event_t *evt)
|
||||
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),
|
||||
heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM));
|
||||
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),
|
||||
heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM));
|
||||
break;
|
||||
case HTTP_EVENT_HEADER_SENT:
|
||||
ESP_LOGD(TAG, "HTTP_EVENT_HEADER_SENT");
|
||||
@@ -184,7 +183,7 @@ esp_err_t init_config(esp_http_client_config_t * conf, const char * url){
|
||||
memset(conf, 0x00, sizeof(esp_http_client_config_t));
|
||||
conf->cert_pem = (char *)server_cert_pem_start;
|
||||
conf->event_handler = _http_event_handler;
|
||||
conf->buffer_size = 1024*2;
|
||||
conf->buffer_size = 1024*8;
|
||||
conf->disable_auto_redirect=true;
|
||||
conf->skip_cert_common_name_check = false;
|
||||
conf->url = strdup(url);
|
||||
@@ -207,26 +206,26 @@ void ota_task(void *pvParameter)
|
||||
return ;
|
||||
}
|
||||
ota_status.current_url= strdup(passedURL);
|
||||
init_config(&config,ota_status.current_url);
|
||||
// init_config(&config,ota_status.current_url);
|
||||
|
||||
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
|
||||
ESP_LOGE(TAG,"Redirect check failed to identify target URL. Bailing out");
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
//
|
||||
// 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
|
||||
// ESP_LOGE(TAG,"Redirect check failed to identify target URL. Bailing out");
|
||||
// vTaskDelete(NULL);
|
||||
// }
|
||||
ESP_LOGD(TAG,"Calling esp_https_ota");
|
||||
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);
|
||||
vTaskDelay(500/ portTICK_RATE_MS);
|
||||
esp_err_t err = esp_https_ota(&ota_config);
|
||||
if (err == ESP_OK) {
|
||||
snprintf(ota_status.status_text,sizeof(ota_status.status_text)-1,"Success!");
|
||||
wifi_manager_refresh_ota_json();
|
||||
@@ -279,7 +278,7 @@ void start_ota(const char * bin_url)
|
||||
ESP_LOGI(TAG, "Waiting for other processes to start");
|
||||
vTaskDelay(2500/ portTICK_RATE_MS);
|
||||
ESP_LOGI(TAG, "Starting ota: %s", urlPtr);
|
||||
ret=xTaskCreate(&ota_task, "ota_task", 1024*10,(void *) urlPtr, 4, NULL);
|
||||
ret=xTaskCreate(&ota_task, "ota_task", 1024*20,(void *) urlPtr, 4, NULL);
|
||||
if (ret != pdPASS) {
|
||||
ESP_LOGI(TAG, "create thread %s failed", "ota_task");
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ function to process requests, decode URLs, serve files, etc. etc.
|
||||
|
||||
/* @brief tag used for ESP serial console messages */
|
||||
static const char TAG[] = "http_server";
|
||||
static const char json_start[] = "{ \"recovery\": %u, \"autoexec\": %u, \"list\": [";
|
||||
static const char json_start[] = "{ \"autoexec\": %u, \"list\": [";
|
||||
static const char json_end[] = "]}";
|
||||
static const char template[] = "{ \"%s\": \"%s\" }";
|
||||
static const char array_separator[]=",";
|
||||
@@ -312,7 +312,7 @@ void http_server_netconn_serve(struct netconn *conn) {
|
||||
|
||||
netconn_write(conn, http_ok_json_no_cache_hdr, sizeof(http_ok_json_no_cache_hdr) - 1, NETCONN_NOCOPY);
|
||||
autoexec_flag = wifi_manager_get_flag();
|
||||
snprintf(config_buffer,locbuflen-1, json_start, RECOVERY_APPLICATION, autoexec_flag);
|
||||
snprintf(config_buffer,locbuflen-1, json_start, autoexec_flag);
|
||||
netconn_write(conn, config_buffer, strlen(config_buffer), NETCONN_NOCOPY);
|
||||
|
||||
ESP_LOGI(TAG, "About to get config from flash");
|
||||
|
||||
@@ -73,6 +73,8 @@ wifi_ap_record_t *accessp_records;
|
||||
char *accessp_json = NULL;
|
||||
char *ip_info_json = NULL;
|
||||
wifi_config_t* wifi_manager_config_sta = NULL;
|
||||
static update_reason_code_t last_update_reason_code=0;
|
||||
|
||||
|
||||
void (**cb_ptr_arr)(void*) = NULL;
|
||||
|
||||
@@ -414,11 +416,18 @@ void wifi_manager_clear_ip_info_json(){
|
||||
|
||||
void wifi_manager_generate_ip_info_json(update_reason_code_t update_reason_code){
|
||||
wifi_config_t *config = wifi_manager_get_wifi_sta_config();
|
||||
if(update_reason_code == UPDATE_OTA) {
|
||||
update_reason_code = last_update_reason_code;
|
||||
}
|
||||
else
|
||||
{
|
||||
last_update_reason_code = update_reason_code;
|
||||
}
|
||||
if(config){
|
||||
#if RECOVERY_APPLICATION
|
||||
const char ip_info_json_format[] = ",\"ip\":\"%s\",\"netmask\":\"%s\",\"gw\":\"%s\",\"urc\":%d,\"project_name\":\"%s\",\"version\":\"%s\", \"ota_dsc\":\"%s\", \"ota_pct\":%u}\n";
|
||||
const char ip_info_json_format[] = ",\"ip\":\"%s\",\"netmask\":\"%s\",\"gw\":\"%s\",\"urc\":%d,\"project_name\":\"%s\",\"version\":\"%s\", \"ota_dsc\":\"%s\", \"ota_pct\":%u,\"recovery\": 1}\n";
|
||||
#else
|
||||
const char ip_info_json_format[] = ",\"ip\":\"%s\",\"netmask\":\"%s\",\"gw\":\"%s\",\"urc\":%d,\"project_name\":\"%s\",\"version\":\"%s\"}\n";
|
||||
const char ip_info_json_format[] = ",\"ip\":\"%s\",\"netmask\":\"%s\",\"gw\":\"%s\",\"urc\":%d,\"project_name\":\"%s\",\"version\":\"%s\",\"recovery\": 0}\n";
|
||||
#endif
|
||||
memset(ip_info_json, 0x00, JSON_IP_INFO_SIZE);
|
||||
const esp_app_desc_t* desc = esp_ota_get_app_description();
|
||||
@@ -900,6 +909,12 @@ void wifi_manager( void * pvParameters ){
|
||||
if(cb_ptr_arr[msg.code]) (*cb_ptr_arr[msg.code])(NULL);
|
||||
|
||||
break;
|
||||
case EVENT_REFRESH_OTA:
|
||||
if(wifi_manager_lock_json_buffer( portMAX_DELAY )){
|
||||
wifi_manager_generate_ip_info_json( UPDATE_OTA );
|
||||
wifi_manager_unlock_json_buffer();
|
||||
}
|
||||
break;
|
||||
|
||||
case ORDER_START_WIFI_SCAN:
|
||||
ESP_LOGD(TAG, "MESSAGE: ORDER_START_WIFI_SCAN");
|
||||
@@ -1155,7 +1170,6 @@ void wifi_manager( void * pvParameters ){
|
||||
if(cb_ptr_arr[msg.code]) (*cb_ptr_arr[msg.code])(NULL);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
|
||||
@@ -226,7 +226,8 @@ typedef enum update_reason_code_t {
|
||||
UPDATE_CONNECTION_OK = 0,
|
||||
UPDATE_FAILED_ATTEMPT = 1,
|
||||
UPDATE_USER_DISCONNECT = 2,
|
||||
UPDATE_LOST_CONNECTION = 3
|
||||
UPDATE_LOST_CONNECTION = 3,
|
||||
UPDATE_OTA=4
|
||||
}update_reason_code_t;
|
||||
|
||||
typedef enum connection_request_made_by_code_t{
|
||||
|
||||
Reference in New Issue
Block a user