Dramatically simplified OTA enable check in safemode
Rather than auto-enable OTA if not already enabled in safemode, changed the logic to simply rollback to previous app if OTA was used to download a sketch that does not itself have OTA enabled, unless OTA was previously enabled without safemode. To do: Delete all complicated SpanOTA logic that (unsuccessfully) tried to track OTA status and check SHA246 partition codes to determine if reboot was OTA or Serial. None of this is need, but some of the code may be useful for other things in the future.
This commit is contained in:
parent
1b0c4835cb
commit
ffdf0296c6
|
|
@ -154,6 +154,16 @@ void Span::begin(Category catID, const char *displayName, const char *hostNameBa
|
||||||
Serial.print(displayName);
|
Serial.print(displayName);
|
||||||
Serial.print("\n\n");
|
Serial.print("\n\n");
|
||||||
|
|
||||||
|
uint8_t otaRequired=0;
|
||||||
|
nvs_get_u8(otaNVS,"OTA_REQUIRED",&otaRequired);
|
||||||
|
nvs_set_u8(otaNVS,"OTA_REQUIRED",0);
|
||||||
|
nvs_commit(otaNVS);
|
||||||
|
if(otaRequired && !spanOTA.enabled){
|
||||||
|
Serial.printf("\n\n*** OTA SAFE MODE ALERT: OTA REQUIRED BUT NOT ENABLED. ROLLING BACK TO PREVIOUS APPLICATION ***\n\n");
|
||||||
|
delay(100);
|
||||||
|
esp_ota_mark_app_invalid_rollback_and_reboot();
|
||||||
|
}
|
||||||
|
|
||||||
} // begin
|
} // begin
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
@ -531,35 +541,35 @@ 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
|
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
|
mdns_service_txt_item_set("_hap","_tcp","sh",setupHash); // Step 4: broadcast the resulting Setup Hash
|
||||||
|
|
||||||
boolean autoEnable=false;
|
// boolean autoEnable=false;
|
||||||
uint32_t otaStatus=0;
|
// uint32_t otaStatus=0;
|
||||||
nvs_get_u32(otaNVS,"OTASTATUS",&otaStatus);
|
// nvs_get_u32(otaNVS,"OTASTATUS",&otaStatus);
|
||||||
|
//
|
||||||
Serial.printf("*** OTA STATUS: %d ***\n\r",otaStatus);
|
// Serial.printf("*** OTA STATUS: %d ***\n\r",otaStatus);
|
||||||
|
//
|
||||||
if(otaStatus&SpanOTA::OTA_DOWNLOADED ){ // if OTA was used for last download
|
// if(otaStatus&SpanOTA::OTA_DOWNLOADED ){ // if OTA was used for last download
|
||||||
otaStatus^=SpanOTA::OTA_DOWNLOADED; // turn off OTA_DOWNLOADED flag
|
// 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
|
// 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
|
// autoEnable=true; // activate auto-enable
|
||||||
|
//
|
||||||
} else if(otaStatus&SpanOTA::OTA_BOOTED ){ // if OTA was present in last boot, but not used for download
|
// } 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(!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
|
// 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
|
// autoEnable=true; // activate auto-enable
|
||||||
} else { // code has changed - do not activate auto-enable
|
// } else { // code has changed - do not activate auto-enable
|
||||||
otaStatus^=SpanOTA::OTA_BOOTED; // turn off OTA_DOWNLOADED flag
|
// otaStatus^=SpanOTA::OTA_BOOTED; // turn off OTA_DOWNLOADED flag
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
nvs_set_u32(otaNVS,"OTASTATUS",otaStatus);
|
// nvs_set_u32(otaNVS,"OTASTATUS",otaStatus);
|
||||||
nvs_commit(otaNVS);
|
// nvs_commit(otaNVS);
|
||||||
|
//
|
||||||
if(autoEnable){
|
// if(autoEnable){
|
||||||
spanOTA.enabled=true;
|
// spanOTA.enabled=true;
|
||||||
spanOTA.auth=otaStatus&SpanOTA::OTA_AUTHORIZED;
|
// spanOTA.auth=otaStatus&SpanOTA::OTA_AUTHORIZED;
|
||||||
spanOTA.safeLoad=true;
|
// spanOTA.safeLoad=true;
|
||||||
Serial.printf("OTA Safe Mode: OTA Auto-Enabled\n");
|
// Serial.printf("OTA Safe Mode: OTA Auto-Enabled\n");
|
||||||
}
|
// }
|
||||||
|
|
||||||
if(spanOTA.enabled){
|
if(spanOTA.enabled){
|
||||||
if(esp_ota_get_running_partition()!=esp_ota_get_next_update_partition(NULL)){
|
if(esp_ota_get_running_partition()!=esp_ota_get_next_update_partition(NULL)){
|
||||||
|
|
@ -2037,7 +2047,8 @@ void SpanOTA::start(){
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
||||||
void SpanOTA::end(){
|
void SpanOTA::end(){
|
||||||
nvs_set_u32(homeSpan.otaNVS, "OTASTATUS", OTA_DOWNLOADED | OTA_BOOTED | (auth?OTA_AUTHORIZED:0) | (safeLoad?OTA_SAFEMODE:0));
|
// 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);
|
nvs_commit(homeSpan.otaNVS);
|
||||||
Serial.printf(" DONE! Rebooting...\n");
|
Serial.printf(" DONE! Rebooting...\n");
|
||||||
homeSpan.statusLED.off();
|
homeSpan.statusLED.off();
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,8 @@ void setup() {
|
||||||
homeSpan.setPortNum(1201);
|
homeSpan.setPortNum(1201);
|
||||||
// homeSpan.setMaxConnections(6);
|
// homeSpan.setMaxConnections(6);
|
||||||
// homeSpan.setQRID("One1");
|
// homeSpan.setQRID("One1");
|
||||||
homeSpan.enableOTA();
|
// homeSpan.enableOTA(false,false);
|
||||||
homeSpan.setSketchVersion("OTA Test 5");
|
homeSpan.setSketchVersion("OTA Test 8");
|
||||||
homeSpan.setWifiCallback(wifiEstablished);
|
homeSpan.setWifiCallback(wifiEstablished);
|
||||||
|
|
||||||
new SpanUserCommand('d',"- My Description",userCom1);
|
new SpanUserCommand('d',"- My Description",userCom1);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue