[ONB] Fix failsafe mode (#2080)

Erasing the nvs before the start of WM prevent WM from starting, revert a part of #2075
Also remove the erase from setupWiFiManager method

Co-authored-by: Florian <1technophile@users.noreply.github.com>
This commit is contained in:
FlorianandFlorian authored and GitHub committed 2024-10-04 17:02:50 -05:00
1 parent 4e090eda3c
commit 898b5e6213
2 files changed
+12 -19

No files matched your search

+2 -1
View File
@@ -64,6 +64,7 @@ void MeasureGPIOInput() {
resetTime = millis(); resetTime = millis();
} else if ((millis() - resetTime) > 3000) { } else if ((millis() - resetTime) > 3000) {
Log.trace(F("Button Held" CR)); Log.trace(F("Button Held" CR));
gatewayState = GatewayState::WAITING_ONBOARDING;
// Switching off the relay during reset or failsafe operations // Switching off the relay during reset or failsafe operations
# ifdef ZactuatorONOFF # ifdef ZactuatorONOFF
uint8_t level = digitalRead(ACTUATOR_ONOFF_GPIO); uint8_t level = digitalRead(ACTUATOR_ONOFF_GPIO);
@@ -72,7 +73,7 @@ void MeasureGPIOInput() {
} }
# endif # endif
Log.notice(F("Erasing ESP Config, restarting" CR)); Log.notice(F("Erasing ESP Config, restarting" CR));
setupWiFiManager(true); erase(true);
} }
} else { } else {
resetTime = 0; resetTime = 0;
+10 -18
View File
@@ -1393,13 +1393,14 @@ void setup() {
#if defined(ESPWifiManualSetup) #if defined(ESPWifiManualSetup)
setupWiFiFromBuild(); setupWiFiFromBuild();
#else #else
if (loadConfigFromFlash()) { if (loadConfigFromFlash()) { // Config present
Log.notice(F("Config loaded from flash" CR)); Log.notice(F("Config loaded from flash" CR));
# ifdef ESP32_ETHERNET # ifdef ESP32_ETHERNET
setup_ethernet_esp32(); setup_ethernet_esp32();
# endif # endif
if (!failSafeMode && !ethConnected) setupWiFiManager(false); // If not in failSafeMode and no connection to the network with Ethernet, launch the wifi manager
} else { if (!failSafeMode && !ethConnected) setupWiFiManager();
} else { // No config in flash
# ifdef ESP32_ETHERNET # ifdef ESP32_ETHERNET
setup_ethernet_esp32(); setup_ethernet_esp32();
# endif # endif
@@ -1411,7 +1412,7 @@ void setup() {
Log.notice(F("No config in flash, launching wifi manager" CR)); 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 // 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 #endif
@@ -1879,7 +1880,7 @@ void blockingWaitForReset() {
ActuatorTrigger(); ActuatorTrigger();
} }
# endif # 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 // 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 // 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()) { if (SPIFFS.begin()) {
@@ -1887,9 +1888,6 @@ void blockingWaitForReset() {
if (SPIFFS.exists("/config.json")) { if (SPIFFS.exists("/config.json")) {
Log.notice(F("Erasing ESP Config, restarting" CR)); Log.notice(F("Erasing ESP Config, restarting" CR));
erase(true); erase(true);
} else {
Log.notice(F("Erasing ESP Config, without restart" CR));
erase(false);
} }
} }
delay(30000); delay(30000);
@@ -1897,9 +1895,8 @@ void blockingWaitForReset() {
Log.notice(F("Going into failsafe mode without peripherals" CR)); 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 // Failsafe mode enable to connect to Wifi or change the firmware without the peripherals setup
failSafeMode = true; failSafeMode = true;
setupWiFiManager(false); setupWiFiManager();
} }
ESPRestart(5);
} }
} }
} }
@@ -2179,13 +2176,10 @@ bool loadConfigFromFlash() {
return result; return result;
} }
void setupWiFiManager(bool reset_settings) { void setupWiFiManager() {
delay(10); delay(10);
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
if (reset_settings)
erase(true);
# ifdef USE_MAC_AS_GATEWAY_NAME # ifdef USE_MAC_AS_GATEWAY_NAME
String s = WiFi.macAddress(); String s = WiFi.macAddress();
snprintf(WifiManager_ssid, MAC_NAME_MAX_LEN, "%s_%.2s%.2s", Gateway_Short_Name, s.c_str(), s.c_str() + 3); 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 if (strstr(cmd, restartCmd) != NULL) { //restart
ESPRestart(5); ESPRestart(5);
} else if (strstr(cmd, eraseCmd) != NULL) { //erase and restart } else if (strstr(cmd, eraseCmd) != NULL) { //erase and restart
#ifndef ESPWifiManualSetup erase(true);
setupWiFiManager(true); } else if (strstr(cmd, statusCmd) != NULL) {
#endif
} else if (strstr(cmd, statusCmd) != NULL) { //erase and restart
publishState = true; publishState = true;
} }
} }