diff --git a/.cproject b/.cproject index 3fd2bc8c..7792b1c8 100644 --- a/.cproject +++ b/.cproject @@ -239,7 +239,7 @@ - + diff --git a/components/cmd_system/cmd_system.c b/components/cmd_system/cmd_system.c index c6e15e7e..4f94e94b 100644 --- a/components/cmd_system/cmd_system.c +++ b/components/cmd_system/cmd_system.c @@ -26,6 +26,7 @@ #include "sdkconfig.h" #include "esp_partition.h" #include "esp_ota_ops.h" +#include "platform_esp32.h" #ifdef CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS #define WITH_TASKS_INFO 1 @@ -112,6 +113,7 @@ esp_err_t guided_boot(esp_partition_subtype_t partition_subtype) if(it == NULL){ ESP_LOGE(TAG,"Unable initialize partition iterator!"); + set_status_message(ERROR, "Reboot failed. Cannot iterate through partitions"); } else { @@ -120,10 +122,12 @@ esp_err_t guided_boot(esp_partition_subtype_t partition_subtype) ESP_LOGI(TAG, "Found partition type %u",partition_subtype); esp_ota_set_boot_partition(partition); bFound=true; + set_status_message(WARNING, "Rebooting!"); } else { ESP_LOGE(TAG,"partition type %u not found! Unable to reboot to recovery.",partition_subtype); + set_status_message(ERROR, "Partition not found."); } esp_partition_iterator_release(it); if(bFound) { @@ -131,6 +135,7 @@ esp_err_t guided_boot(esp_partition_subtype_t partition_subtype) esp_restart(); } } + return ESP_OK; } diff --git a/components/cmd_system/component.mk b/components/cmd_system/component.mk index e0e9f4c1..f9949433 100644 --- a/components/cmd_system/component.mk +++ b/components/cmd_system/component.mk @@ -8,3 +8,4 @@ # COMPONENT_ADD_INCLUDEDIRS := . +COMPONENT_EXTRA_INCLUDES += $(PROJECT_PATH)/main/ diff --git a/components/wifi-manager/http_server.c b/components/wifi-manager/http_server.c index 0e264ade..d4037325 100644 --- a/components/wifi-manager/http_server.c +++ b/components/wifi-manager/http_server.c @@ -218,31 +218,6 @@ err_t http_server_nvs_dump(struct netconn *conn, nvs_type_t nvs_type, bool * bFi } nvs_json = cJSON_CreateObject(); num_buffer = malloc(NUM_BUFFER_LEN); -// -// -// cJSON_AddItemToObject(ip_info_cjson, "version", cJSON_CreateString(desc->version)); -// cJSON_AddNumberToObject(ip_info_cjson,"recovery", RECOVERY_APPLICATION ); -// cJSON_AddNumberToObject(ip_info_cjson, "urc", update_reason_code); -// if(config){ -// cJSON_AddItemToObject(ip_info_cjson, "ssid", cJSON_CreateString((char *)config->sta.ssid)); -// -// if(update_reason_code == UPDATE_CONNECTION_OK){ -// /* rest of the information is copied after the ssid */ -// tcpip_adapter_ip_info_t ip_info; -// ESP_ERROR_CHECK(tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info)); -// cJSON_AddItemToObject(ip_info_cjson, "ip", cJSON_CreateString(ip4addr_ntoa(&ip_info.ip))); -// cJSON_AddItemToObject(ip_info_cjson, "netmask", cJSON_CreateString(ip4addr_ntoa(&ip_info.netmask))); -// cJSON_AddItemToObject(ip_info_cjson, "gw", cJSON_CreateString(ip4addr_ntoa(&ip_info.gw))); -// } -// } -// -// -// cJSON_AddItemToObject(ip_info_cjson, "ota_dsc", cJSON_CreateString(ota_get_status())); -// cJSON_AddNumberToObject(ip_info_cjson,"ota_pct", ota_get_pct_complete() ); -// -// cJSON_AddItemToObject(ip_info_cjson, "Jack", cJSON_CreateString(JACK_LEVEL)); -// -// nvs_iterator_t it = nvs_entry_find(NVS_PARTITION_NAME, NULL, nvs_type); if (it == NULL) { diff --git a/components/wifi-manager/wifi_manager.c b/components/wifi-manager/wifi_manager.c index 64ac9267..604afa3d 100644 --- a/components/wifi-manager/wifi_manager.c +++ b/components/wifi-manager/wifi_manager.c @@ -30,7 +30,7 @@ Contains the freeRTOS task and all necessary support */ #include "wifi_manager.h" - +#include "platform_esp32.h" #include #include #include @@ -318,7 +318,6 @@ bool wifi_manager_fetch_wifi_sta_config(){ } - cJSON * wifi_manager_get_new_json(cJSON **old){ cJSON * root=*old; if(root!=NULL){ @@ -561,6 +560,20 @@ void wifi_manager_connect_async(){ wifi_manager_send_message(ORDER_CONNECT_STA, (void*)CONNECTION_REQUEST_USER); } +void set_status_message(message_severity_t severity, const char * message){ + if(ip_info_cjson==NULL){ + ip_info_cjson = wifi_manager_get_new_json(&ip_info_cjson); + } + if(ip_info_cjson==NULL){ + ESP_LOGE(TAG,"Error setting status message. Unable to allocate cJSON."); + return; + } + cJSON * item=cJSON_GetObjectItem(ip_info_cjson, "message"); + item = wifi_manager_get_new_json(&item); + cJSON_AddItemToObject(item, "severity", cJSON_CreateString(severity==INFO?"INFO":severity==WARNING?"WARNING":severity==ERROR?"ERROR":"" )); + cJSON_AddItemToObject(item, "text", cJSON_CreateString(message)); +} + char* wifi_manager_get_ip_info_json(){ return cJSON_Print(ip_info_cjson); diff --git a/main/platform_esp32.h b/main/platform_esp32.h index 3443e069..0291154c 100644 --- a/main/platform_esp32.h +++ b/main/platform_esp32.h @@ -31,4 +31,9 @@ extern bool wait_for_wifi(); extern void console_start(); extern pthread_cond_t wifi_connect_suspend_cond; extern pthread_t wifi_connect_suspend_mutex; - +typedef enum { + INFO, + WARNING, + ERROR +} message_severity_t; +extern void set_status_message(message_severity_t severity, const char * message);