From 7ddbfd55ccde2bc381f585770b44c137f745b469 Mon Sep 17 00:00:00 2001 From: Gregg Date: Mon, 7 Mar 2022 22:02:23 -0600 Subject: [PATCH] Slight OTA cleanup plus confirmed that you cannot enable ROLLBACK in Arduino-ESP32 Since much of the Arduino-ESP32 library is precompiled, you cannot use -DCONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE to define this during compile time (it gets defined but is not used by the precompiled libraries). TO DO: create an NVS entry that flags whether last update was via OTA. If so, automatically enable OTA regardless of enableOTA setting. This would ensure that OTA cannot be disabled accidentally by uploading a non-enabledOTA sketch to remote device. --- src/HomeSpan.cpp | 16 ++++++++++------ src/src.ino | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index eb63e71..aec9753 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -44,7 +44,7 @@ using namespace Utils; HAPClient **hap; // HAP Client structure containing HTTP client connections, parsing routines, and state variables (global-scoped variable) Span homeSpan; // HAP Attributes database and all related control functions for this Accessory (global-scoped variable) HapCharacteristics hapChars; // Instantiation of all HAP Characteristics (used to create SpanCharacteristics) -int otaPercent; +int otaPercent; // local variable to keep track of %progress when OTA is loading new sketch /////////////////////////////// // Span // @@ -135,13 +135,11 @@ void Span::begin(Category catID, const char *displayName, const char *hostNameBa Serial.print(__DATE__); Serial.print(" "); Serial.print(__TIME__); - - Serial.printf("\nOTA Partition: %s",otaEnabled?esp_ota_get_running_partition()->label:"N/A"); - + Serial.print("\n\nDevice Name: "); Serial.print(displayName); Serial.print("\n\n"); - + } // begin /////////////////////////////// @@ -559,15 +557,21 @@ void Span::checkConnect(){ Serial.print(displayName); Serial.print(" at "); Serial.print(WiFi.localIP()); + esp_ota_img_states_t otaState; + esp_ota_get_state_partition(esp_ota_get_running_partition(),&otaState); +// Serial.printf("\nPartition: %s State: %X",esp_ota_get_running_partition()->label,otaState); Serial.print("\nAuthorization Password: "); Serial.print(otaAuth?"Enabled\n\n":"DISABLED!\n\n"); } else { Serial.print("\n*** WARNING: Can't start OTA Server - Partition table used to compile this sketch is not configured for OTA.\n\n"); + otaEnabled=false; } } + + mdns_service_txt_item_set("_hap","_tcp","ota",otaEnabled?"yes":"no"); // OTA status (info only - NOT used by HAP) if(webLog.isEnabled){ - mdns_service_txt_item_set("_hap","_tcp","logURL",webLog.statusURL.c_str()+4); // Web Log Enabled (info only - NOT used by HAP) + mdns_service_txt_item_set("_hap","_tcp","logURL",webLog.statusURL.c_str()+4); // Web Log status (info only - NOT used by HAP) Serial.printf("Web Logging enabled at http://%s.local:%d%swith max number of entries=%d\n\n",hostName,tcpPortNum,webLog.statusURL.c_str()+4,webLog.maxEntries); webLog.initTime(); diff --git a/src/src.ino b/src/src.ino index 2476f58..8ac2f66 100644 --- a/src/src.ino +++ b/src/src.ino @@ -21,7 +21,7 @@ void setup() { homeSpan.setPortNum(1201); // homeSpan.setMaxConnections(6); // homeSpan.setQRID("One1"); -// homeSpan.enableOTA(); + homeSpan.enableOTA(); homeSpan.setSketchVersion("OTA Test 5"); homeSpan.setWifiCallback(wifiEstablished);