Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions src/WifiControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) + ",";
}
Expand All @@ -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) + ",";
}
Expand All @@ -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()
Expand All @@ -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())
{
Expand All @@ -184,10 +193,14 @@ void WifiControl::loop()
if (_status != WL_CONNECTED)
{
infraToAPFailover();
return;
}
}

if (_tcpServer == nullptr || _udp == nullptr)
{
return;
}

_mount->loop();

tcpLoop();
Expand All @@ -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.");
}
Expand Down
1 change: 1 addition & 0 deletions src/WifiControl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
Loading