Browse Source

Backup EEPROM before performing OTA (#1808, #1809)

* [Fix] Backing up EEPROM before performing OTA.For fixing - [#1808]

* Guard ArduinoOTA, different handler for async
master
arihant daga 5 years ago
committed by Max Prokhorov
parent
commit
fbf2b71749
3 changed files with 15 additions and 0 deletions
  1. +7
    -0
      code/espurna/eeprom.ino
  2. +5
    -0
      code/espurna/nofuss.ino
  3. +3
    -0
      code/espurna/ota.ino

+ 7
- 0
code/espurna/eeprom.ino View File

@ -23,6 +23,9 @@ void eepromRotate(bool value) {
DEBUG_MSG_P(PSTR("[EEPROM] Disabling EEPROM rotation\n")); DEBUG_MSG_P(PSTR("[EEPROM] Disabling EEPROM rotation\n"));
} }
EEPROMr.rotate(value); 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; _eeprom_commit = true;
} }
void eepromBackup(uint32_t index){
EEPROMr.backup(index);
}
#if TERMINAL_SUPPORT #if TERMINAL_SUPPORT
void _eepromInitCommands() { void _eepromInitCommands() {


+ 5
- 0
code/espurna/nofuss.ino View File

@ -122,6 +122,9 @@ void nofussSetup() {
// Disabling EEPROM rotation to prevent writing to EEPROM after the upgrade // Disabling EEPROM rotation to prevent writing to EEPROM after the upgrade
eepromRotate(false); eepromRotate(false);
// Force backup right now, because NoFUSS library will immediatly reset on success
eepromBackup(0);
} }
if (code == NOFUSS_FILESYSTEM_UPDATE_ERROR) { if (code == NOFUSS_FILESYSTEM_UPDATE_ERROR) {
@ -145,6 +148,8 @@ void nofussSetup() {
#if WEB_SUPPORT #if WEB_SUPPORT
wsSend_P(PSTR("{\"action\": \"reload\"}")); wsSend_P(PSTR("{\"action\": \"reload\"}"));
#endif #endif
// TODO: NoFUSS will reset the board after this callback returns.
// Maybe this should be optional
nice_delay(100); nice_delay(100);
} }


+ 3
- 0
code/espurna/ota.ino View File

@ -251,6 +251,9 @@ void otaSetup() {
// Disabling EEPROM rotation to prevent writing to EEPROM after the upgrade // Disabling EEPROM rotation to prevent writing to EEPROM after the upgrade
eepromRotate(false); 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")); DEBUG_MSG_P(PSTR("[OTA] Start\n"));
#if WEB_SUPPORT #if WEB_SUPPORT


Loading…
Cancel
Save