Merge branch 'Over_The_Air_Update' of github.com:sle118/squeezelite-esp32 into Over_The_Air_Update

This commit is contained in:
Christian Herzog
2019-09-29 19:13:56 +02:00
16 changed files with 2493 additions and 39 deletions

View File

@@ -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");

View File

@@ -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;

View File

@@ -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{