From 64091571801ec9f1349e8d4ce6ff25d04c13e609 Mon Sep 17 00:00:00 2001 From: Gregg Date: Mon, 14 Mar 2022 22:01:28 -0500 Subject: [PATCH] Completed all SpanOTA safemode logic and cleaned up previous iterations of the logic Must document in safemode in API as well as discuss in OTA documentation. --- src/HomeSpan.cpp | 44 +------------------------------------------- src/HomeSpan.h | 6 ------ 2 files changed, 1 insertion(+), 49 deletions(-) diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index 8e9a3e8..d6e5e38 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -137,18 +137,7 @@ void Span::begin(Category catID, const char *displayName, const char *hostNameBa Serial.print(" "); Serial.print(__TIME__); - uint8_t prevSHA[32]={0}; - uint8_t sha256[32]; - if(!nvs_get_blob(otaNVS,"SHA256",NULL,&len)) // get previous app SHA256 (if it exists) - nvs_get_blob(otaNVS,"SHA256",prevSHA,&len); - esp_partition_get_sha256(esp_ota_get_running_partition(),sha256); // get current app SHA256 - newCode=(memcmp(prevSHA,sha256,32)!=0); // set newCode flag based on comparison of previous and current SHA256 values - nvs_set_blob(otaNVS,"SHA256",sha256,sizeof(sha256)); // save current SHA256 - nvs_commit(otaNVS); - - esp_ota_img_states_t otaState; - esp_ota_get_state_partition(esp_ota_get_running_partition(),&otaState); - Serial.printf("\nPartition: %s (%s-0x%0X)",esp_ota_get_running_partition()->label,newCode?"NEW":"REBOOTED",otaState); + Serial.printf("\nPartition: %s",esp_ota_get_running_partition()->label); Serial.print("\n\nDevice Name: "); Serial.print(displayName); @@ -541,36 +530,6 @@ void Span::checkConnect(){ mbedtls_base64_encode((uint8_t *)setupHash,9,&len,hashOutput,4); // Step 3: Encode the first 4 bytes of hashOutput in base64, which results in an 8-character, null-terminated, setupHash mdns_service_txt_item_set("_hap","_tcp","sh",setupHash); // Step 4: broadcast the resulting Setup Hash -// boolean autoEnable=false; -// uint32_t otaStatus=0; -// nvs_get_u32(otaNVS,"OTASTATUS",&otaStatus); -// -// Serial.printf("*** OTA STATUS: %d ***\n\r",otaStatus); -// -// if(otaStatus&SpanOTA::OTA_DOWNLOADED ){ // if OTA was used for last download -// otaStatus^=SpanOTA::OTA_DOWNLOADED; // turn off OTA_DOWNLOADED flag -// if(!spanOTA.enabled && (otaStatus&SpanOTA::OTA_SAFEMODE)) // if OTA is not enabled, but it was last enabled in safe mode -// autoEnable=true; // activate auto-enable -// -// } else if(otaStatus&SpanOTA::OTA_BOOTED ){ // if OTA was present in last boot, but not used for download -// if(!newCode){ // if code has NOT changed -// if(!spanOTA.enabled && (otaStatus&SpanOTA::OTA_SAFEMODE)) // if OTA is not enabled, but it was last enabled in safe mode -// autoEnable=true; // activate auto-enable -// } else { // code has changed - do not activate auto-enable -// otaStatus^=SpanOTA::OTA_BOOTED; // turn off OTA_DOWNLOADED flag -// } -// } -// -// nvs_set_u32(otaNVS,"OTASTATUS",otaStatus); -// nvs_commit(otaNVS); -// -// if(autoEnable){ -// spanOTA.enabled=true; -// spanOTA.auth=otaStatus&SpanOTA::OTA_AUTHORIZED; -// spanOTA.safeLoad=true; -// Serial.printf("OTA Safe Mode: OTA Auto-Enabled\n"); -// } - if(spanOTA.enabled){ if(esp_ota_get_running_partition()!=esp_ota_get_next_update_partition(NULL)){ ArduinoOTA.setHostname(hostName); @@ -2047,7 +2006,6 @@ void SpanOTA::start(){ /////////////////////////////// void SpanOTA::end(){ -// nvs_set_u32(homeSpan.otaNVS, "OTASTATUS", OTA_DOWNLOADED | OTA_BOOTED | (auth?OTA_AUTHORIZED:0) | (safeLoad?OTA_SAFEMODE:0)); nvs_set_u8(homeSpan.otaNVS,"OTA_REQUIRED",safeLoad); nvs_commit(homeSpan.otaNVS); Serial.printf(" DONE! Rebooting...\n"); diff --git a/src/HomeSpan.h b/src/HomeSpan.h index e61bdf8..c970652 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -128,12 +128,6 @@ struct SpanWebLog{ // optional web status/log data /////////////////////////////// struct SpanOTA{ // manages OTA process - enum { // flag to keep track of OTA status between reboots - OTA_BOOTED=1, - OTA_DOWNLOADED=2, - OTA_AUTHORIZED=4, - OTA_SAFEMODE=8 - }; char otaPwd[33]; // MD5 Hash of OTA password, represented as a string of hexidecimal characters