diff --git a/src/WifiControl.cpp b/src/WifiControl.cpp index 2d177682..e0ba3efd 100644 --- a/src/WifiControl.cpp +++ b/src/WifiControl.cpp @@ -111,10 +111,12 @@ String WifiControl::getStatus() } else if (WIFI_MODE == WIFI_MODE_ATTEMPT_INFRASTRUCTURE_FAIL_TO_AP) { - result += "Infra-Fail-To-AP,"; + result += _failedOver ? "Access Point," : "Infra-Fail-To-AP,"; } - if (WIFI_MODE != WIFI_MODE_AP_ONLY) + // Station-interface fields only apply while we are (still) running as a station + bool stationMode = (WIFI_MODE != WIFI_MODE_AP_ONLY) && !_failedOver; + if (stationMode) { result += wifiStatus(WiFi.status()) + ","; } @@ -124,7 +126,7 @@ String WifiControl::getStatus() #endif result += getIP() + ":" + WIFI_PORT + ","; - if (WIFI_MODE != WIFI_MODE_AP_ONLY) + if (stationMode) { result += String(WIFI_INFRASTRUCTURE_MODE_SSID) + ","; } @@ -147,9 +149,15 @@ void WifiControl::establishServers() String WifiControl::getIP() { - return WIFI_MODE == WIFI_MODE_DISABLED ? "NONE" - : WIFI_MODE == WIFI_MODE_AP_ONLY ? WiFi.softAPIP().toString() - : WiFi.localIP().toString(); + if (WIFI_MODE == WIFI_MODE_DISABLED) + { + return "NONE"; + } + if (WIFI_MODE == WIFI_MODE_AP_ONLY || _failedOver) + { + return WiFi.softAPIP().toString(); + } + return WiFi.localIP().toString(); } void WifiControl::clearCmd() @@ -165,7 +173,8 @@ void WifiControl::loop() return; } - if (WIFI_MODE != WIFI_MODE_AP_ONLY) + // Monitor the station interface until we operate as an access point + if (WIFI_MODE != WIFI_MODE_AP_ONLY && !_failedOver) { if (_status != WiFi.status()) { @@ -184,10 +193,14 @@ void WifiControl::loop() if (_status != WL_CONNECTED) { infraToAPFailover(); - return; } } + if (_tcpServer == nullptr || _udp == nullptr) + { + return; + } + _mount->loop(); tcpLoop(); @@ -201,6 +214,7 @@ void WifiControl::infraToAPFailover() WiFi.disconnect(); startAccessPointMode(); _infraStart = 0; + _failedOver = true; LOG(DEBUG_WIFI, "[WIFI]: Could not connect to Infra, Starting AP."); } diff --git a/src/WifiControl.hpp b/src/WifiControl.hpp index 3039617e..233cc136 100644 --- a/src/WifiControl.hpp +++ b/src/WifiControl.hpp @@ -46,6 +46,7 @@ class WifiControl unsigned long _infraStart = 0; unsigned long _infraWait = 30000; // 30 second timeout for + bool _failedOver = false; // true once failover mode has switched to the access point static constexpr size_t _defaultCapacity = 32; static constexpr size_t _maxCapacity = 128; };