Skip to content

Commit

Permalink
[SYS] Fix erase function for ESP8266
Browse files Browse the repository at this point in the history
And remove restart parameter as it is not used (the ESP always restart after erase for our use cases)
  • Loading branch information
1technophile committed Nov 8, 2024
1 parent e2641f4 commit eb34daf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion main/ZsensorGPIOInput.ino
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void MeasureGPIOInput() {
}
# endif
Log.notice(F("Erasing ESP Config, restarting" CR));
erase(true);
eraseConfig();
}
} else {
resetTime = 0;
Expand Down
4 changes: 2 additions & 2 deletions main/ZwebUI.ino
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ QueueHandle_t webUIQueue;
WebServer server(80);

/*------------------- External functions ----------------------*/
extern void erase(bool restart);
extern void eraseConfig();
extern unsigned long uptime();

/*------------------- Web Console Globals ----------------------*/
Expand Down Expand Up @@ -1237,7 +1237,7 @@ void handleRT() {
response += String(buffer);
server.send(200, "text/html", response);

erase(true);
eraseConfig();
} else {
handleCN();
}
Expand Down
16 changes: 6 additions & 10 deletions main/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1901,7 +1901,7 @@ void blockingWaitForReset() {
Log.trace(F("mounted file system" CR));
if (SPIFFS.exists("/config.json")) {
Log.notice(F("Erasing ESP Config, restarting" CR));
erase(true);
eraseConfig();
}
}
delay(30000);
Expand Down Expand Up @@ -2742,9 +2742,9 @@ float intTemperatureRead() {
#endif

/*
Erase flash and restart the ESP
Erase config and restart the ESP
*/
void erase(bool restart) {
void eraseConfig() {
#ifdef SecondaryModule
// Erase the secondary module config
String eraseCmdStr = "{\"cmd\":\"" + String(eraseCmd) + "\"}";
Expand All @@ -2756,15 +2756,11 @@ void erase(bool restart) {

#if defined(ESP8266)
WiFi.disconnect(true);
# ifndef ESPWifiManualSetup
wifiManager.resetSettings();
# endif
delay(5000);
ESP.eraseConfig();
#else
nvs_flash_erase();
#endif
if (restart)
ESPRestart(0);
ESPRestart(0);
}

String stateMeasures() {
Expand Down Expand Up @@ -3354,7 +3350,7 @@ void XtoSYS(const char* topicOri, JsonObject& SYSdata) { // json object decoding
if (strstr(cmd, restartCmd) != NULL) { //restart
ESPRestart(5);
} else if (strstr(cmd, eraseCmd) != NULL) { //erase and restart
erase(true);
eraseConfig();
} else if (strstr(cmd, statusCmd) != NULL) {
publishState = true;
}
Expand Down

0 comments on commit eb34daf

Please sign in to comment.