From 055c9a6ca389df33fdf87e88a7d888638478b630 Mon Sep 17 00:00:00 2001 From: Florian <1technophile@users.noreply.github.com> Date: Fri, 4 Oct 2024 16:34:00 -0500 Subject: [PATCH] [ONB] Fix failsafe mode Erasing the nvs before the start of WM prevent WM from starting, revert a part of #2075 Also remove the erase from setupWiFiManager method --- main/ZsensorGPIOInput.ino | 3 ++- main/main.ino | 28 ++++++++++------------------ 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/main/ZsensorGPIOInput.ino b/main/ZsensorGPIOInput.ino index f35b545b4d..46a91e2479 100644 --- a/main/ZsensorGPIOInput.ino +++ b/main/ZsensorGPIOInput.ino @@ -64,6 +64,7 @@ void MeasureGPIOInput() { resetTime = millis(); } else if ((millis() - resetTime) > 3000) { Log.trace(F("Button Held" CR)); + gatewayState = GatewayState::WAITING_ONBOARDING; // Switching off the relay during reset or failsafe operations # ifdef ZactuatorONOFF uint8_t level = digitalRead(ACTUATOR_ONOFF_GPIO); @@ -72,7 +73,7 @@ void MeasureGPIOInput() { } # endif Log.notice(F("Erasing ESP Config, restarting" CR)); - setupWiFiManager(true); + erase(true); } } else { resetTime = 0; diff --git a/main/main.ino b/main/main.ino index 9464e455b6..35eaa35ce6 100644 --- a/main/main.ino +++ b/main/main.ino @@ -1393,13 +1393,14 @@ void setup() { #if defined(ESPWifiManualSetup) setupWiFiFromBuild(); #else - if (loadConfigFromFlash()) { + if (loadConfigFromFlash()) { // Config present Log.notice(F("Config loaded from flash" CR)); # ifdef ESP32_ETHERNET setup_ethernet_esp32(); # endif - if (!failSafeMode && !ethConnected) setupWiFiManager(false); - } else { + // If not in failSafeMode and no connection to the network with Ethernet, launch the wifi manager + if (!failSafeMode && !ethConnected) setupWiFiManager(); + } else { // No config in flash # ifdef ESP32_ETHERNET setup_ethernet_esp32(); # endif @@ -1411,7 +1412,7 @@ void setup() { Log.notice(F("No config in flash, launching wifi manager" CR)); // In failSafeMode we don't want to setup wifi manager as it has already been done before - if (!failSafeMode) setupWiFiManager(false); + if (!failSafeMode) setupWiFiManager(); } #endif @@ -1879,7 +1880,7 @@ void blockingWaitForReset() { ActuatorTrigger(); } # endif - ledManager.setMode(-1, -1, LEDManager::STATIC, LED_WAITING_ONBOARD_COLOR, -1); + gatewayState = GatewayState::WAITING_ONBOARDING; // Checking if the flash has already been erased to identify if we erase it or go into failsafe mode // going to failsafe mode is done by doing a long button press from a state where the flash has already been erased if (SPIFFS.begin()) { @@ -1887,9 +1888,6 @@ void blockingWaitForReset() { if (SPIFFS.exists("/config.json")) { Log.notice(F("Erasing ESP Config, restarting" CR)); erase(true); - } else { - Log.notice(F("Erasing ESP Config, without restart" CR)); - erase(false); } } delay(30000); @@ -1897,9 +1895,8 @@ void blockingWaitForReset() { Log.notice(F("Going into failsafe mode without peripherals" CR)); // Failsafe mode enable to connect to Wifi or change the firmware without the peripherals setup failSafeMode = true; - setupWiFiManager(false); + setupWiFiManager(); } - ESPRestart(5); } } } @@ -2179,13 +2176,10 @@ bool loadConfigFromFlash() { return result; } -void setupWiFiManager(bool reset_settings) { +void setupWiFiManager() { delay(10); WiFi.mode(WIFI_STA); - if (reset_settings) - erase(true); - # ifdef USE_MAC_AS_GATEWAY_NAME String s = WiFi.macAddress(); snprintf(WifiManager_ssid, MAC_NAME_MAX_LEN, "%s_%.2s%.2s", Gateway_Short_Name, s.c_str(), s.c_str() + 3); @@ -3346,10 +3340,8 @@ 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 -#ifndef ESPWifiManualSetup - setupWiFiManager(true); -#endif - } else if (strstr(cmd, statusCmd) != NULL) { //erase and restart + erase(true); + } else if (strstr(cmd, statusCmd) != NULL) { publishState = true; } }