From bf952da9b97d3f4200b1a4cf24afb40224f6f565 Mon Sep 17 00:00:00 2001 From: Mainfurr <90922330+Mainfurr@users.noreply.github.com> Date: Mon, 26 Oct 2026 10:58:51 +0000 Subject: [PATCH 1/3] Add optional STA rejoin from the setup fallback New setting ESP_STA_FALLBACK_RETRY (pos 1257, "sta fallback retry" in network/sta, default off). When it is on and the STA connection failed over to the setup AP, ESP3D scans every 2 minutes (while no client is connected to the AP) and restarts the network once the configured SSID is visible again. If that attempt fails it falls back to setup mode as before. Settings saved by older builds read 0xFF at the new position; the default is written at startup when the stored value is not valid. --- esp3d/src/core/commands/ESP400.cpp | 5 ++ esp3d/src/core/esp3d_settings.cpp | 15 ++++++ esp3d/src/include/esp3d_defines.h | 1 + esp3d/src/modules/wifi/wificonfig.cpp | 69 +++++++++++++++++++++++++++ esp3d/src/modules/wifi/wificonfig.h | 4 ++ 5 files changed, 94 insertions(+) diff --git a/esp3d/src/core/commands/ESP400.cpp b/esp3d/src/core/commands/ESP400.cpp index a1ff9e66..98e9c5d9 100644 --- a/esp3d/src/core/commands/ESP400.cpp +++ b/esp3d/src/core/commands/ESP400.cpp @@ -300,6 +300,11 @@ void ESP3DCommands::ESP400(int cmd_params_pos, ESP3DMessage* msg) { "sta fallback mode", FallbackValues, FallbackLabels, sizeof(FallbackValues) / sizeof(char*), -1, -1, -1, nullptr, true, target, requestId); + // Rejoin the STA network from the setup fallback when it is back + dispatchSetting(json, "network/sta", ESP_STA_FALLBACK_RETRY, + "sta fallback retry", YesNoValues, YesNoLabels, + sizeof(YesNoValues) / sizeof(char*), -1, -1, -1, nullptr, + true, target, requestId); #endif // WIFI_FEATURE #if defined(WIFI_FEATURE) // AP SSID network/ap diff --git a/esp3d/src/core/esp3d_settings.cpp b/esp3d/src/core/esp3d_settings.cpp index 8802da5c..66949cd5 100644 --- a/esp3d/src/core/esp3d_settings.cpp +++ b/esp3d/src/core/esp3d_settings.cpp @@ -145,6 +145,7 @@ #define DEFAULT_AUTO_NOTIFICATION_STATE "1" #define DEFAULT_SECURE_SERIAL "1" #define DEFAULT_BOOT_RADIO_STATE "1" +#define DEFAULT_STA_FALLBACK_RETRY "0" // default int values #define DEFAULT_ESP_INT "0" @@ -204,6 +205,7 @@ uint16_t ESP3DSettingsData[] = {ESP_RADIO_MODE, ESP_STA_SSID, ESP_BOOT_RADIO_STATE, ESP_STA_FALLBACK_MODE, + ESP_STA_FALLBACK_RETRY, ESP_AP_SSID, ESP_AP_PASSWORD, ESP_STA_IP_VALUE, @@ -284,6 +286,13 @@ bool ESP3DSettings::begin() { if (GetSettingsVersion() == -1) { return false; } +#if defined(WIFI_FEATURE) + // Settings saved by older builds have no value here yet (0xFF) + if (!isValidByteSetting(readByte(ESP_STA_FALLBACK_RETRY), + ESP_STA_FALLBACK_RETRY)) { + writeByte(ESP_STA_FALLBACK_RETRY, atoi(DEFAULT_STA_FALLBACK_RETRY)); + } +#endif // WIFI_FEATURE // get target FW ESP3DSettings::GetFirmwareTarget(true); ESP3DSettings::isVerboseBoot(true); @@ -964,6 +973,7 @@ bool ESP3DSettings::isValidByteSetting(uint8_t value, case ESP_SECURE_SERIAL: case ESP_CALIBRATION: case ESP_BOOT_RADIO_STATE: + case ESP_STA_FALLBACK_RETRY: if (value == (uint8_t)ESP3DState::off || value == (uint8_t)ESP3DState::on) { return true; @@ -1179,6 +1189,7 @@ const ESP3DSettingDescription *ESP3DSettings::getSettingPtr( case ESP_SECURE_SERIAL: case ESP_BOOT_RADIO_STATE: case ESP_STA_FALLBACK_MODE: + case ESP_STA_FALLBACK_RETRY: case ESP_ETH_STA_FALLBACK_MODE: case ESP_SERIAL_BRIDGE_ON: case ESP_STA_IP_MODE: @@ -1268,6 +1279,7 @@ const ESP3DSettingDescription *ESP3DSettings::getSettingPtr( case ESP_BOOT_RADIO_STATE: case ESP_ETH_STA_FALLBACK_MODE: case ESP_STA_FALLBACK_MODE: + case ESP_STA_FALLBACK_RETRY: case ESP_SERIAL_BRIDGE_ON: case ESP_ETH_STA_IP_MODE: case ESP_STA_IP_MODE: @@ -1436,6 +1448,9 @@ const ESP3DSettingDescription *ESP3DSettings::getSettingPtr( case ESP_STA_FALLBACK_MODE: setting.default_val = DEFAULT_STA_FALLBACK_MODE; break; + case ESP_STA_FALLBACK_RETRY: + setting.default_val = DEFAULT_STA_FALLBACK_RETRY; + break; case ESP_SERIAL_BRIDGE_ON: setting.default_val = DEFAULT_SERIAL_BRIDGE_ON; break; diff --git a/esp3d/src/include/esp3d_defines.h b/esp3d/src/include/esp3d_defines.h index 152f4dde..0bbbe30f 100644 --- a/esp3d/src/include/esp3d_defines.h +++ b/esp3d/src/include/esp3d_defines.h @@ -141,6 +141,7 @@ typedef uint ESP3DSettingIndex; #define ESP_ETH_STA_GATEWAY_VALUE 1245 // 4 bytes xxx.xxx.xxx.xxx #define ESP_ETH_STA_DNS_VALUE 1249 // 4 bytes xxx.xxx.xxx.xxx #define ESP_USB_SERIAL_BAUD_RATE 1253 // 4 bytes= int +#define ESP_STA_FALLBACK_RETRY 1257 // 1 byte = flag // Hidden password #define HIDDEN_PASSWORD "********" diff --git a/esp3d/src/modules/wifi/wificonfig.cpp b/esp3d/src/modules/wifi/wificonfig.cpp index 867dc90c..c33aee9c 100644 --- a/esp3d/src/modules/wifi/wificonfig.cpp +++ b/esp3d/src/modules/wifi/wificonfig.cpp @@ -39,8 +39,16 @@ esp_netif_t *get_esp_interface_netif(esp_interface_t interface); const uint8_t DEFAULT_AP_MASK_VALUE[] = {255, 255, 255, 0}; +// How often the setup fallback looks for the STA network again +#ifndef STA_FALLBACK_RETRY_INTERVAL +#define STA_FALLBACK_RETRY_INTERVAL 120000 +#endif // STA_FALLBACK_RETRY_INTERVAL + IPAddress WiFiConfig::_ap_gateway; IPAddress WiFiConfig::_ap_subnet; +bool WiFiConfig::_inStaFallback = false; +bool WiFiConfig::_retryScanRunning = false; +uint32_t WiFiConfig::_lastRetry = 0; const char* WiFiConfig::hostname() { static String tmp; @@ -310,6 +318,8 @@ bool WiFiConfig::started() { return (WiFi.getMode() != WIFI_OFF); } bool WiFiConfig::begin(int8_t& espMode) { bool res = false; end(); + _inStaFallback = false; + _retryScanRunning = false; esp3d_log("Starting Wifi Config"); if (ESP3DSettings::isVerboseBoot()) { esp3d_commands.dispatch("Starting WiFi", ESP3DClientType::all_clients, @@ -342,6 +352,8 @@ bool WiFiConfig::begin(int8_t& espMode) { } esp3d_log("Starting AP mode in setup mode"); res = StartAP(true); + _inStaFallback = res; + _lastRetry = millis(); } else { // let setup to handle the change if (ESP3DSettings::isVerboseBoot()) { @@ -380,6 +392,12 @@ void WiFiConfig::end() { */ void WiFiConfig::handle() { + if (_inStaFallback) { + handleFallbackRetry(); + if (_retryScanRunning || !_inStaFallback) { + return; + } + } // to avoid mixed mode if (WiFi.getMode() == WIFI_AP_STA) { if (WiFi.scanComplete() != WIFI_SCAN_RUNNING) { @@ -388,6 +406,57 @@ void WiFiConfig::handle() { } } +/** + * While the setup AP runs as STA fallback, look for the STA network now and + * then and restart the network when it is visible again. Only when enabled, + * and only while no client uses the setup AP, because scanning changes + * channels and would disturb that client. + */ +void WiFiConfig::handleFallbackRetry() { + if (_retryScanRunning) { + int16_t count = WiFi.scanComplete(); + if (count == WIFI_SCAN_RUNNING) { + return; + } + _retryScanRunning = false; + _lastRetry = millis(); + bool found = false; + if (count > 0) { + String SSID = ESP3DSettings::readString(ESP_STA_SSID); + for (int16_t i = 0; i < count && !found; i++) { + found = (WiFi.SSID(i) == SSID); + } + } + WiFi.scanDelete(); + if (found) { + esp3d_log("STA network is back, leaving setup mode"); + esp3d_commands.dispatch("STA network found, reconnecting", + ESP3DClientType::all_clients, no_id, + ESP3DMessageType::unique, ESP3DClientType::system, + ESP3DAuthenticationLevel::admin); + // Falls back to setup mode again if the connection fails + NetConfig::begin(); + } + return; + } + if (ESP3DSettings::readByte(ESP_STA_FALLBACK_RETRY) != + (uint8_t)ESP3DState::on || + ESP3DSettings::readByte(ESP_RADIO_MODE) != ESP_WIFI_STA) { + return; + } + if (millis() - _lastRetry < STA_FALLBACK_RETRY_INTERVAL) { + return; + } + _lastRetry = millis(); + if (WiFi.softAPgetStationNum() > 0) { + return; + } + esp3d_log("Looking for the STA network"); + if (WiFi.scanNetworks(true) == WIFI_SCAN_RUNNING) { + _retryScanRunning = true; + } +} + const char* WiFiConfig::getSleepModeString() { #ifdef ARDUINO_ARCH_ESP32 if (WiFi.getSleep()) { diff --git a/esp3d/src/modules/wifi/wificonfig.h b/esp3d/src/modules/wifi/wificonfig.h index f5b0eb18..bd5e6b26 100644 --- a/esp3d/src/modules/wifi/wificonfig.h +++ b/esp3d/src/modules/wifi/wificonfig.h @@ -78,8 +78,12 @@ class WiFiConfig { private: static bool ConnectSTA2AP(); + static void handleFallbackRetry(); static IPAddress _ap_gateway; static IPAddress _ap_subnet; + static bool _inStaFallback; + static bool _retryScanRunning; + static uint32_t _lastRetry; }; #endif //_WIFI_CONFIG_H From a0b9f0973363bdd97ea3c9a08433af4dc0567b1a Mon Sep 17 00:00:00 2001 From: Mainfurr <90922330+Mainfurr@users.noreply.github.com> Date: Mon, 26 Oct 2026 13:51:08 +0000 Subject: [PATCH 2/3] Add [ESP109] for the STA fallback retry and report it on serial [ESP109] shows or sets the sta fallback retry setting (ON/OFF, admin to set), so it can be turned off without [ESP401]. When the setup fallback starts with the retry on, "Waiting for STA network" is sent to all clients, next to the existing "STA network found, reconnecting". Documented in espXXX.md, Commands.md and authentication.md. --- docs/Commands.md | 3 + docs/authentication.md | 1 + docs/espXXX.md | 40 ++++++++++++ esp3d/src/core/commands/ESP0.cpp | 4 +- esp3d/src/core/commands/ESP109.cpp | 94 +++++++++++++++++++++++++++ esp3d/src/core/esp3d_commands.cpp | 5 ++ esp3d/src/core/esp3d_commands.h | 1 + esp3d/src/modules/wifi/wificonfig.cpp | 8 +++ 8 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 esp3d/src/core/commands/ESP109.cpp diff --git a/docs/Commands.md b/docs/Commands.md index ec8cc67e..d6d6c6f4 100644 --- a/docs/Commands.md +++ b/docs/Commands.md @@ -46,6 +46,9 @@ The json format is * Set/Get AP channel `[ESP108] json= pwd=` +* Set/Get sta rejoin from setup fallback which can be ON, OFF + `[ESP109] json= pwd=` + * Set/Get radio state which can be WIFI-STA, WIFI-AP, BT, ETH-STA, ETH-AP, OFF `[ESP110] json= pwd=` diff --git a/docs/authentication.md b/docs/authentication.md index 1b24830c..83e780d3 100644 --- a/docs/authentication.md +++ b/docs/authentication.md @@ -81,6 +81,7 @@ Here the scope of right for each authentication level: | ESP106 | No | No | Set | Set | | ESP107 | No | No | Get | Get/Set | | ESP108 | No | No | Get | Get/Set | +| ESP109 | No | No | Get | Get/Set | | ESP110 | No | No | Get | Get/Set | | ESP111 | No | No | Get | Get | | ESP112 | No | No | Get | Get/Set | diff --git a/docs/espXXX.md b/docs/espXXX.md index 70a8d271..dc5d9366 100644 --- a/docs/espXXX.md +++ b/docs/espXXX.md @@ -375,6 +375,46 @@ the admin password if authentication is enabled * `status` status of command, should be `ok` * `data` content of response, here the channel ++++ +archetype = "section" +title = "[ESP109]" +weight = 800 ++++ +Get/Set station rejoin from the setup fallback which can be ON, OFF + +When it is ON and the station connection failed over to the setup access point, ESP3D looks for the station network every 2 minutes (only while no client is connected to the access point) and reconnects when it is visible again. If that attempt fails it goes back to setup mode. `Waiting for STA network` and `STA network found, reconnecting` are sent to all clients, including serial. + +## Input +`[ESP109] json= pwd=` + +* json=no +the output format +can be in JSON or plain text + +* pwd= +the admin password if authentication is enabled + +* mode + * if mode is empty, it will display current mode + * if mode is not empty, it will set the setting mode: `ON` or `OFF` + + +## Output + +- In json format + +```json +{ + "cmd":"109", + "status":"ok", + "data":"OFF" +} +``` + +* `cmd` Id of requested command, should be `109` +* `status` status of command, should be `ok` +* `data` content of response, here the mode + +++ archetype = "section" title = "[ESP110]" diff --git a/esp3d/src/core/commands/ESP0.cpp b/esp3d/src/core/commands/ESP0.cpp index 8f5da15d..f4df62be 100644 --- a/esp3d/src/core/commands/ESP0.cpp +++ b/esp3d/src/core/commands/ESP0.cpp @@ -35,6 +35,8 @@ const char* help[] = { "[ESP106](Password) - set AP password", "[ESP107](IP) - display/set AP IP", "[ESP108](Chanel) - display/set AP chanel", + "[ESP109](State) - display/set sta rejoin from setup fallback which can " + "be ON, OFF", #endif // WIFI_FEATURE #if defined(WIFI_FEATURE) || defined(BLUETOOTH_FEATURE) || defined(ETH_FEATURE) "[ESP110](State) - display/set radio state which can be BT, WIFI-STA, " @@ -206,7 +208,7 @@ const uint cmdlist[] = { #if defined(WIFI_FEATURE) 102, 103, 104, - 105, 106, 107, 108, + 105, 106, 107, 108, 109, #endif // WIFI_FEATURE #if defined(WIFI_FEATURE) || defined(BLUETOOTH_FEATURE) || defined(ETH_FEATURE) 110, diff --git a/esp3d/src/core/commands/ESP109.cpp b/esp3d/src/core/commands/ESP109.cpp new file mode 100644 index 00000000..bf179599 --- /dev/null +++ b/esp3d/src/core/commands/ESP109.cpp @@ -0,0 +1,94 @@ +/* + ESP109.cpp - ESP3D command class + + Copyright (c) 2014 Luc Lebosse. All rights reserved. + + This code is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This code is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with This code; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#include "../../include/esp3d_config.h" +#if defined(WIFI_FEATURE) +#include "../../modules/authentication/authentication_service.h" +#include "../esp3d_commands.h" +#include "../esp3d_settings.h" + +// Get/Set STA rejoin from the setup fallback which can be ON, OFF +//[ESP109] json= pwd= +#define COMMAND_ID 109 +void ESP3DCommands::ESP109(int cmd_params_pos, ESP3DMessage* msg) { + ESP3DClientType target = msg->origin; + ESP3DRequest requestId = msg->request_id; + (void)requestId; + msg->target = target; + msg->origin = ESP3DClientType::command; + bool hasError = false; + String error_msg = "Invalid parameters"; + String ok_msg = "ok"; + bool json = hasTag(msg, cmd_params_pos, "json"); + String tmpstr; + uint8_t byteValue = (uint8_t)-1; +#if defined(AUTHENTICATION_FEATURE) + if (msg->authentication_level == ESP3DAuthenticationLevel::guest) { + msg->authentication_level = ESP3DAuthenticationLevel::not_authenticated; + dispatchAuthenticationError(msg, COMMAND_ID, json); + return; + } +#endif // AUTHENTICATION_FEATURE + tmpstr = get_clean_param(msg, cmd_params_pos); + if (tmpstr.length() == 0) { + byteValue = ESP3DSettings::readByte(ESP_STA_FALLBACK_RETRY); + if (byteValue == (uint8_t)ESP3DState::off) { + ok_msg = "OFF"; + } else if (byteValue == (uint8_t)ESP3DState::on) { + ok_msg = "ON"; + } else { + ok_msg = "Unknown"; + } + } else { +#if defined(AUTHENTICATION_FEATURE) + if (msg->authentication_level != ESP3DAuthenticationLevel::admin) { + dispatchAuthenticationError(msg, COMMAND_ID, json); + return; + } +#endif // AUTHENTICATION_FEATURE + if (tmpstr == "OFF") { + byteValue = (uint8_t)ESP3DState::off; + } else if (tmpstr == "ON") { + byteValue = (uint8_t)ESP3DState::on; + } else { + byteValue = (uint8_t)-1; // unknow flag so put outof range value + } + esp3d_log( + "got %s param for a value of %d, is valid %d", tmpstr.c_str(), + byteValue, + ESP3DSettings::isValidByteSetting(byteValue, ESP_STA_FALLBACK_RETRY)); + if (ESP3DSettings::isValidByteSetting(byteValue, ESP_STA_FALLBACK_RETRY)) { + esp3d_log("Value %d is valid", byteValue); + if (!ESP3DSettings::writeByte(ESP_STA_FALLBACK_RETRY, byteValue)) { + hasError = true; + error_msg = "Set value failed"; + } + } else { + hasError = true; + error_msg = "Invalid parameter"; + } + } + + if (!dispatchAnswer(msg, COMMAND_ID, json, hasError, + hasError ? error_msg.c_str() : ok_msg.c_str())) { + esp3d_log_e("Error sending response to clients"); + } +} + +#endif // WIFI_FEATURE \ No newline at end of file diff --git a/esp3d/src/core/esp3d_commands.cpp b/esp3d/src/core/esp3d_commands.cpp index bc6bd5a2..9b6dff61 100644 --- a/esp3d/src/core/esp3d_commands.cpp +++ b/esp3d/src/core/esp3d_commands.cpp @@ -437,6 +437,11 @@ void ESP3DCommands::execute_internal_command(int cmd, int cmd_params_pos, case 108: ESP108(cmd_params_pos, msg); break; + // Rejoin STA network from the setup fallback + //[ESP109]pwd= + case 109: + ESP109(cmd_params_pos, msg); + break; #endif // WIFI_FEATURE #if defined(WIFI_FEATURE) || defined(BLUETOOTH_FEATURE) || defined(ETH_FEATURE) diff --git a/esp3d/src/core/esp3d_commands.h b/esp3d/src/core/esp3d_commands.h index 3925b957..63601734 100644 --- a/esp3d/src/core/esp3d_commands.h +++ b/esp3d/src/core/esp3d_commands.h @@ -61,6 +61,7 @@ class ESP3DCommands { void ESP106(int cmd_params_pos, ESP3DMessage* msg); void ESP107(int cmd_params_pos, ESP3DMessage* msg); void ESP108(int cmd_params_pos, ESP3DMessage* msg); + void ESP109(int cmd_params_pos, ESP3DMessage* msg); #endif // WIFI_FEATURE #if defined(WIFI_FEATURE) || defined(BLUETOOTH_FEATURE) || defined(ETH_FEATURE) void ESP110(int cmd_params_pos, ESP3DMessage* msg); diff --git a/esp3d/src/modules/wifi/wificonfig.cpp b/esp3d/src/modules/wifi/wificonfig.cpp index c33aee9c..76ff5b63 100644 --- a/esp3d/src/modules/wifi/wificonfig.cpp +++ b/esp3d/src/modules/wifi/wificonfig.cpp @@ -354,6 +354,14 @@ bool WiFiConfig::begin(int8_t& espMode) { res = StartAP(true); _inStaFallback = res; _lastRetry = millis(); + if (res && ESP3DSettings::readByte(ESP_STA_FALLBACK_RETRY) == + (uint8_t)ESP3DState::on) { + esp3d_commands.dispatch("Waiting for STA network", + ESP3DClientType::all_clients, no_id, + ESP3DMessageType::unique, + ESP3DClientType::system, + ESP3DAuthenticationLevel::admin); + } } else { // let setup to handle the change if (ESP3DSettings::isVerboseBoot()) { From 20de041b4c85f4c5bcb20266c0a8def2e564d741 Mon Sep 17 00:00:00 2001 From: Mainfurr <90922330+Mainfurr@users.noreply.github.com> Date: Mon, 26 Oct 2026 14:08:06 +0000 Subject: [PATCH 3/3] Reject invalid values in [ESP109] isValidByteSetting() returns true for any value of an on/off setting, so [ESP109]MAYBE stored 255. Only ON and OFF are written now, anything else gets "Invalid parameter". The 0xFF init check for the setting compares the value directly for the same reason. --- esp3d/src/core/commands/ESP109.cpp | 11 +++++------ esp3d/src/core/esp3d_settings.cpp | 5 +++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/esp3d/src/core/commands/ESP109.cpp b/esp3d/src/core/commands/ESP109.cpp index bf179599..d22d4863 100644 --- a/esp3d/src/core/commands/ESP109.cpp +++ b/esp3d/src/core/commands/ESP109.cpp @@ -69,12 +69,11 @@ void ESP3DCommands::ESP109(int cmd_params_pos, ESP3DMessage* msg) { } else { byteValue = (uint8_t)-1; // unknow flag so put outof range value } - esp3d_log( - "got %s param for a value of %d, is valid %d", tmpstr.c_str(), - byteValue, - ESP3DSettings::isValidByteSetting(byteValue, ESP_STA_FALLBACK_RETRY)); - if (ESP3DSettings::isValidByteSetting(byteValue, ESP_STA_FALLBACK_RETRY)) { - esp3d_log("Value %d is valid", byteValue); + esp3d_log("got %s param for a value of %d", tmpstr.c_str(), byteValue); + // isValidByteSetting() accepts any value for on/off settings, so only + // ON and OFF are written + if (byteValue == (uint8_t)ESP3DState::off || + byteValue == (uint8_t)ESP3DState::on) { if (!ESP3DSettings::writeByte(ESP_STA_FALLBACK_RETRY, byteValue)) { hasError = true; error_msg = "Set value failed"; diff --git a/esp3d/src/core/esp3d_settings.cpp b/esp3d/src/core/esp3d_settings.cpp index 66949cd5..2fc128f8 100644 --- a/esp3d/src/core/esp3d_settings.cpp +++ b/esp3d/src/core/esp3d_settings.cpp @@ -288,8 +288,9 @@ bool ESP3DSettings::begin() { } #if defined(WIFI_FEATURE) // Settings saved by older builds have no value here yet (0xFF) - if (!isValidByteSetting(readByte(ESP_STA_FALLBACK_RETRY), - ESP_STA_FALLBACK_RETRY)) { + uint8_t staFallbackRetry = readByte(ESP_STA_FALLBACK_RETRY); + if (staFallbackRetry != (uint8_t)ESP3DState::off && + staFallbackRetry != (uint8_t)ESP3DState::on) { writeByte(ESP_STA_FALLBACK_RETRY, atoi(DEFAULT_STA_FALLBACK_RETRY)); } #endif // WIFI_FEATURE