Skip to content

Commit

Permalink
Backup EEPROM before performing OTA (#1808, #1809)
Browse files Browse the repository at this point in the history
* [Fix] Backing up EEPROM before performing OTA.For fixing - [#1808]

* Guard ArduinoOTA, different handler for async
  • Loading branch information
arihantdaga authored and mcspr committed Jul 17, 2019
1 parent 6765fd8 commit fbf2b71
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions code/espurna/eeprom.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -54,6 +57,10 @@ void eepromCommit() {
_eeprom_commit = true;
}

void eepromBackup(uint32_t index){
EEPROMr.backup(index);
}

#if TERMINAL_SUPPORT

void _eepromInitCommands() {
Expand Down
5 changes: 5 additions & 0 deletions code/espurna/nofuss.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}

Expand Down
3 changes: 3 additions & 0 deletions code/espurna/ota.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fbf2b71

Please sign in to comment.