diff --git a/README.md b/README.md index 34df84ac..f2526e8b 100644 --- a/README.md +++ b/README.md @@ -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.13.0b-brightgreen.svg)](CHANGELOG.md) +[![version](https://img.shields.io/badge/version-1.13.0c-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) diff --git a/code/espurna/config/version.h b/code/espurna/config/version.h index ed599180..6f2333e7 100644 --- a/code/espurna/config/version.h +++ b/code/espurna/config/version.h @@ -1,5 +1,5 @@ #define APP_NAME "ESPURNA" -#define APP_VERSION "1.13.0b" +#define APP_VERSION "1.13.0c" #define APP_REVISION "db84006" #define APP_AUTHOR "xose.perez@gmail.com" #define APP_WEBSITE "http://tinkerman.cat" diff --git a/code/espurna/eeprom.ino b/code/espurna/eeprom.ino index 237009dd..2e79fcbb 100644 --- a/code/espurna/eeprom.ino +++ b/code/espurna/eeprom.ino @@ -8,12 +8,16 @@ EEPROM MODULE // ----------------------------------------------------------------------------- -bool eepromBackup() { - // Backup data to last sector if we are using more sectors than the +bool eepromRotate(bool value) { + // Enable/disable EEPROM rotation only if we are using more sectors than the // reserved by the memory layout if (EEPROMr.size() > EEPROMr.reserved()) { - DEBUG_MSG_P(PSTR("[EEPROM] Backing up data to last sector\n")); - return EEPROMr.backup(); + if (value) { + DEBUG_MSG_P(PSTR("[EEPROM] Reenabling EEPROM rotation\n")); + } else { + DEBUG_MSG_P(PSTR("[EEPROM] Disabling EEPROM rotation\n")); + } + EEPROMr.rotate(value); } } diff --git a/code/espurna/ota.ino b/code/espurna/ota.ino index 23559aaf..4443431a 100644 --- a/code/espurna/ota.ino +++ b/code/espurna/ota.ino @@ -65,12 +65,12 @@ 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); - nice_delay(100); - ESP.restart(); + deferredReset(100, CUSTOM_RESET_OTA); } else { #ifdef DEBUG_PORT Update.printError(DEBUG_PORT); #endif + eepromRotate(true); } DEBUG_MSG_P(PSTR("[OTA] Disconnected\n")); @@ -134,15 +134,8 @@ 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(); + // Disabling EEPROM rotation to prevent writing to EEPROM after the upgrade + eepromRotate(false); DEBUG_MSG_P(PSTR("[OTA] Downloading %s\n"), _ota_url); char buffer[strlen_P(OTA_REQUEST_TEMPLATE) + strlen(_ota_url) + strlen(_ota_host)]; @@ -225,15 +218,8 @@ 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(); + // Disabling EEPROM rotation to prevent writing to EEPROM after the upgrade + eepromRotate(false); DEBUG_MSG_P(PSTR("[OTA] Start\n")); @@ -249,8 +235,7 @@ void otaSetup() { #if WEB_SUPPORT wsSend_P(PSTR("{\"action\": \"reload\"}")); #endif - nice_delay(100); - ESP.restart(); + deferredReset(100, CUSTOM_RESET_OTA); }); ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { @@ -266,6 +251,7 @@ void otaSetup() { else if (error == OTA_RECEIVE_ERROR) DEBUG_MSG_P(PSTR("Receive Failed\n")); else if (error == OTA_END_ERROR) DEBUG_MSG_P(PSTR("End Failed\n")); #endif + eepromRotate(true); }); ArduinoOTA.begin(); diff --git a/code/espurna/web.ino b/code/espurna/web.ino index 09255f54..3e8447fb 100644 --- a/code/espurna/web.ino +++ b/code/espurna/web.ino @@ -223,9 +223,10 @@ void _onUpgrade(AsyncWebServerRequest *request) { AsyncWebServerResponse *response = request->beginResponse(200, "text/plain", buffer); response->addHeader("Connection", "close"); - if (!Update.hasError()) { - nice_delay(100); - ESP.restart(); + if (Update.hasError()) { + eepromRotate(true); + } else { + deferredReset(100, CUSTOM_RESET_UPGRADE); } request->send(response); @@ -235,15 +236,8 @@ 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(); + // Disabling EEPROM rotation to prevent writing to EEPROM after the upgrade + eepromRotate(false); DEBUG_MSG_P(PSTR("[UPGRADE] Start: %s\n"), filename.c_str()); Update.runAsync(true); diff --git a/code/platformio.ini b/code/platformio.ini index 22342eed..d0e38f68 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -59,7 +59,7 @@ lib_deps = https://github.com/marvinroger/async-mqtt-client#v0.8.1 Brzo I2C https://bitbucket.org/xoseperez/debounceevent.git#2.0.1 - https://github.com/xoseperez/eeprom_rotate#0.9.0 + https://github.com/xoseperez/eeprom_rotate#0.9.1 Embedis https://github.com/plerup/espsoftwareserial#3.4.1 https://github.com/me-no-dev/ESPAsyncTCP#55cd520