diff --git a/code/espurna/eeprom.ino b/code/espurna/eeprom.ino index 2c2e5da9..9b03f80e 100644 --- a/code/espurna/eeprom.ino +++ b/code/espurna/eeprom.ino @@ -23,6 +23,9 @@ void eepromRotate(bool value) { DEBUG_MSG_P(PSTR("[EEPROM] Disabling EEPROM rotation\n")); } EEPROMr.rotate(value); + + // Because .rotate(false) marks EEPROM as dirty, this is equivalent to the .backup(0) + eepromCommit(); } } @@ -54,6 +57,10 @@ void eepromCommit() { _eeprom_commit = true; } +void eepromBackup(uint32_t index){ + EEPROMr.backup(index); +} + #if TERMINAL_SUPPORT void _eepromInitCommands() { diff --git a/code/espurna/nofuss.ino b/code/espurna/nofuss.ino index 5f28007f..aba702de 100644 --- a/code/espurna/nofuss.ino +++ b/code/espurna/nofuss.ino @@ -122,6 +122,9 @@ void nofussSetup() { // Disabling EEPROM rotation to prevent writing to EEPROM after the upgrade eepromRotate(false); + + // Force backup right now, because NoFUSS library will immediatly reset on success + eepromBackup(0); } if (code == NOFUSS_FILESYSTEM_UPDATE_ERROR) { @@ -145,6 +148,8 @@ void nofussSetup() { #if WEB_SUPPORT wsSend_P(PSTR("{\"action\": \"reload\"}")); #endif + // TODO: NoFUSS will reset the board after this callback returns. + // Maybe this should be optional nice_delay(100); } diff --git a/code/espurna/ota.ino b/code/espurna/ota.ino index 0f504adb..69ae888e 100644 --- a/code/espurna/ota.ino +++ b/code/espurna/ota.ino @@ -251,6 +251,9 @@ void otaSetup() { // Disabling EEPROM rotation to prevent writing to EEPROM after the upgrade eepromRotate(false); + // Because ArduinoOTA is synchronous, force backup right now instead of waiting for the next loop() + eepromBackup(0); + DEBUG_MSG_P(PSTR("[OTA] Start\n")); #if WEB_SUPPORT