Browse Source

Update EEPROM_Rotate to 0.9.1 and use rotate(false) before OTA

fastled^2
Xose Pérez 6 years ago
parent
commit
0ef74d0dc0
6 changed files with 25 additions and 41 deletions
  1. +1
    -1
      README.md
  2. +1
    -1
      code/espurna/config/version.h
  3. +8
    -4
      code/espurna/eeprom.ino
  4. +8
    -22
      code/espurna/ota.ino
  5. +6
    -12
      code/espurna/web.ino
  6. +1
    -1
      code/platformio.ini

+ 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. 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. 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/) [![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) [![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) [![codacy](https://img.shields.io/codacy/grade/c9496e25cf07434cba786b462cb15f49/dev.svg)](https://www.codacy.com/app/xoseperez/espurna/dashboard)


+ 1
- 1
code/espurna/config/version.h View File

@ -1,5 +1,5 @@
#define APP_NAME "ESPURNA" #define APP_NAME "ESPURNA"
#define APP_VERSION "1.13.0b"
#define APP_VERSION "1.13.0c"
#define APP_REVISION "db84006" #define APP_REVISION "db84006"
#define APP_AUTHOR "xose.perez@gmail.com" #define APP_AUTHOR "xose.perez@gmail.com"
#define APP_WEBSITE "http://tinkerman.cat" #define APP_WEBSITE "http://tinkerman.cat"


+ 8
- 4
code/espurna/eeprom.ino View File

@ -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 // reserved by the memory layout
if (EEPROMr.size() > EEPROMr.reserved()) { 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);
} }
} }


+ 8
- 22
code/espurna/ota.ino View File

@ -65,12 +65,12 @@ void _otaFrom(const char * host, unsigned int port, const char * url) {
if (Update.end(true)){ if (Update.end(true)){
DEBUG_MSG_P(PSTR("[OTA] Success: %u bytes\n"), _ota_size); DEBUG_MSG_P(PSTR("[OTA] Success: %u bytes\n"), _ota_size);
nice_delay(100);
ESP.restart();
deferredReset(100, CUSTOM_RESET_OTA);
} else { } else {
#ifdef DEBUG_PORT #ifdef DEBUG_PORT
Update.printError(DEBUG_PORT); Update.printError(DEBUG_PORT);
#endif #endif
eepromRotate(true);
} }
DEBUG_MSG_P(PSTR("[OTA] Disconnected\n")); DEBUG_MSG_P(PSTR("[OTA] Disconnected\n"));
@ -134,15 +134,8 @@ void _otaFrom(const char * host, unsigned int port, const char * url) {
} }
#endif #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); DEBUG_MSG_P(PSTR("[OTA] Downloading %s\n"), _ota_url);
char buffer[strlen_P(OTA_REQUEST_TEMPLATE) + strlen(_ota_url) + strlen(_ota_host)]; char buffer[strlen_P(OTA_REQUEST_TEMPLATE) + strlen(_ota_url) + strlen(_ota_host)];
@ -225,15 +218,8 @@ void otaSetup() {
ArduinoOTA.onStart([]() { 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")); DEBUG_MSG_P(PSTR("[OTA] Start\n"));
@ -249,8 +235,7 @@ void otaSetup() {
#if WEB_SUPPORT #if WEB_SUPPORT
wsSend_P(PSTR("{\"action\": \"reload\"}")); wsSend_P(PSTR("{\"action\": \"reload\"}"));
#endif #endif
nice_delay(100);
ESP.restart();
deferredReset(100, CUSTOM_RESET_OTA);
}); });
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { 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_RECEIVE_ERROR) DEBUG_MSG_P(PSTR("Receive Failed\n"));
else if (error == OTA_END_ERROR) DEBUG_MSG_P(PSTR("End Failed\n")); else if (error == OTA_END_ERROR) DEBUG_MSG_P(PSTR("End Failed\n"));
#endif #endif
eepromRotate(true);
}); });
ArduinoOTA.begin(); ArduinoOTA.begin();


+ 6
- 12
code/espurna/web.ino View File

@ -223,9 +223,10 @@ void _onUpgrade(AsyncWebServerRequest *request) {
AsyncWebServerResponse *response = request->beginResponse(200, "text/plain", buffer); AsyncWebServerResponse *response = request->beginResponse(200, "text/plain", buffer);
response->addHeader("Connection", "close"); 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); request->send(response);
@ -235,15 +236,8 @@ void _onUpgradeData(AsyncWebServerRequest *request, String filename, size_t inde
if (!index) { 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()); DEBUG_MSG_P(PSTR("[UPGRADE] Start: %s\n"), filename.c_str());
Update.runAsync(true); Update.runAsync(true);


+ 1
- 1
code/platformio.ini View File

@ -59,7 +59,7 @@ lib_deps =
https://github.com/marvinroger/async-mqtt-client#v0.8.1 https://github.com/marvinroger/async-mqtt-client#v0.8.1
Brzo I2C Brzo I2C
https://bitbucket.org/xoseperez/debounceevent.git#2.0.1 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 Embedis
https://github.com/plerup/espsoftwareserial#3.4.1 https://github.com/plerup/espsoftwareserial#3.4.1
https://github.com/me-no-dev/ESPAsyncTCP#55cd520 https://github.com/me-no-dev/ESPAsyncTCP#55cd520


Loading…
Cancel
Save