Browse Source

Do not write to EEPROM (rotating) after OTA to prevent image corruption

fastled^2
Xose Pérez 6 years ago
parent
commit
9288f411f9
3 changed files with 28 additions and 4 deletions
  1. +1
    -1
      README.md
  2. +18
    -2
      code/espurna/ota.ino
  3. +9
    -1
      code/espurna/web.ino

+ 1
- 1
README.md View File

@ -3,7 +3,7 @@
ESPurna ("spark" in Catalan) is a custom firmware for ESP8285/ESP8266 based smart switches, lights and sensors.
It uses the Arduino Core for ESP8266 framework and a number of 3rd party libraries.
[![version](https://img.shields.io/badge/version-1.12.7a-brightgreen.svg)](CHANGELOG.md)
[![version](https://img.shields.io/badge/version-1.13.0b-brightgreen.svg)](CHANGELOG.md)
[![branch](https://img.shields.io/badge/branch-dev-orange.svg)](https://github.org/xoseperez/espurna/tree/dev/)
[![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=dev)](https://travis-ci.org/xoseperez/espurna)
[![codacy](https://img.shields.io/codacy/grade/c9496e25cf07434cba786b462cb15f49/dev.svg)](https://www.codacy.com/app/xoseperez/espurna/dashboard)


+ 18
- 2
code/espurna/ota.ino View File

@ -65,7 +65,8 @@ void _otaFrom(const char * host, unsigned int port, const char * url) {
if (Update.end(true)){
DEBUG_MSG_P(PSTR("[OTA] Success: %u bytes\n"), _ota_size);
deferredReset(100, CUSTOM_RESET_OTA);
nice_delay(100);
ESP.restart();
} else {
#ifdef DEBUG_PORT
Update.printError(DEBUG_PORT);
@ -133,6 +134,13 @@ void _otaFrom(const char * host, unsigned int port, const char * url) {
}
#endif
// Cache current reset reason
resetReason();
// Set reset reason beforehand,
// to prevent writing to EEPROM after the upgrade
resetReason(CUSTOM_RESET_OTA);
// Backup EEPROM data to last sector
eepromBackup();
@ -217,6 +225,13 @@ void otaSetup() {
ArduinoOTA.onStart([]() {
// Cache current reset reason
resetReason();
// Set reset reason beforehand,
// to prevent writing to EEPROM after the upgrade
resetReason(CUSTOM_RESET_OTA);
// Backup EEPROM data to last sector
eepromBackup();
@ -234,7 +249,8 @@ void otaSetup() {
#if WEB_SUPPORT
wsSend_P(PSTR("{\"action\": \"reload\"}"));
#endif
deferredReset(100, CUSTOM_RESET_OTA);
nice_delay(100);
ESP.restart();
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {


+ 9
- 1
code/espurna/web.ino View File

@ -224,7 +224,8 @@ void _onUpgrade(AsyncWebServerRequest *request) {
AsyncWebServerResponse *response = request->beginResponse(200, "text/plain", buffer);
response->addHeader("Connection", "close");
if (!Update.hasError()) {
deferredReset(100, CUSTOM_RESET_UPGRADE);
nice_delay(100);
ESP.restart();
}
request->send(response);
@ -234,6 +235,13 @@ void _onUpgradeData(AsyncWebServerRequest *request, String filename, size_t inde
if (!index) {
// Cache current reset reason
resetReason();
// Set reset reason beforehand,
// to prevent writing to EEPROM after the upgrade
resetReason(CUSTOM_RESET_UPGRADE);
// Backup EEPROM data to last sector
eepromBackup();


Loading…
Cancel
Save