Skip to content

Commit 5e5c2e1

Browse files
committed
WiFi: Add wifiStationEnabled and wifiUpdateSettings
The routines setup and menuWiFi call wifiUpdateSettings to determine if the SSIDs are available for WiFi station and soft AP and trigger a WiFi station restart. The wifiStationEnabled determines if the WiFi station state machine should start.
1 parent abe9921 commit 5e5c2e1

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed

Firmware/RTK_Everywhere/Developer.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ bool wifiSoftApOn(const char * fileName, uint32_t lineNumber) {return false;}
220220
bool wifiStationOff(const char * fileName, uint32_t lineNumber) {return true;}
221221
bool wifiStationOn(const char * fileName, uint32_t lineNumber) {return false;}
222222
void wifiStopAll() {}
223+
void wifiUpdateSettings() {}
223224
void wifiVerifyTables() {}
224225

225226
#endif // COMPILE_WIFI

Firmware/RTK_Everywhere/RTK_Everywhere.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ unsigned long loraLastIncomingSerial; // Last time a user sent a serial command.
878878

879879
// Display boot times
880880
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
881-
#define MAX_BOOT_TIME_ENTRIES 41
881+
#define MAX_BOOT_TIME_ENTRIES 42
882882
uint8_t bootTimeIndex;
883883
uint32_t bootTime[MAX_BOOT_TIME_ENTRIES];
884884
const char *bootTimeString[MAX_BOOT_TIME_ENTRIES];
@@ -1258,6 +1258,9 @@ void setup()
12581258
DMW_b("beginIdleTasks");
12591259
beginIdleTasks(); // Requires settings. Enable processor load calculations
12601260

1261+
DMW_b("wifiUpdateSettings");
1262+
wifiUpdateSettings();
1263+
12611264
DMW_b("networkBegin");
12621265
networkBegin();
12631266

Firmware/RTK_Everywhere/WiFi.ino

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,9 @@ static int wifiFailedConnectionAttempts = 0; // Count the number of connection a
381381
static bool wifiReconnectRequest; // Set true to request WiFi reconnection
382382

383383
const char * wifiSoftApName = "Soft AP";
384+
bool wifiSoftApSsidSet; // Set when the WiFi soft AP SSID string exists
385+
bool wifiStationRestart; // Restart Wifi station
386+
bool wifiStationSsidSet; // Set when one or more SSID strings exist
384387

385388
// Start timeout
386389
static uint32_t wifiStartTimeout;
@@ -435,11 +438,13 @@ void menuWiFi()
435438
// If we are modifying the SSID table, force restart of WiFi
436439
wifiRestartRequested = true;
437440
wifiFailedConnectionAttempts = 0;
441+
wifiUpdateSettings();
438442
}
439443
else if (incoming == 'a')
440444
{
441445
settings.wifiConfigOverAP ^= 1;
442446
wifiRestartRequested = true;
447+
wifiUpdateSettings();
443448
}
444449
else if (incoming == 'c')
445450
{
@@ -791,6 +796,57 @@ void wifiStartThrottled(NetIndex_t index, uintptr_t parameter, bool debug)
791796
networkSequenceNextEntry(NETWORK_WIFI_STATION, debug);
792797
}
793798

799+
//*********************************************************************
800+
// Determine if WiFi should be running
801+
bool wifiStationEnabled(const char ** reason)
802+
{
803+
bool enabled = false;
804+
static char * reasonBuffer;
805+
806+
do
807+
{
808+
// Verify that at least one SSID value is set
809+
if (wifiStationSsidSet == false)
810+
{
811+
*reason = "SSID not available";
812+
break;
813+
}
814+
815+
// Determine if Wifi is begin restarted
816+
if (wifiStationRestart)
817+
{
818+
wifiStationRestart = false;
819+
*reason = "restart requested";
820+
break;
821+
}
822+
823+
// Is WiFi the highest priority
824+
if (networkIsHighestPriority(NETWORK_WIFI_STATION) == false)
825+
{
826+
// Allocate the reason buffer once
827+
if (reasonBuffer == nullptr)
828+
reasonBuffer = (char *) rtkMalloc(64, "WiFi reasonBuffer");
829+
830+
// Build the reason
831+
if (reasonBuffer)
832+
{
833+
sprintf(reasonBuffer,"is lower priority than %s", networkGetCurrentInterfaceName());
834+
*reason = reasonBuffer;
835+
}
836+
837+
// Allocation failed
838+
else
839+
*reason = "is lower priority";
840+
break;
841+
}
842+
843+
// WiFi should start and continue running
844+
enabled = true;
845+
*reason = "is enabled";
846+
} while (0);
847+
return enabled;
848+
}
849+
794850
//*********************************************************************
795851
// Get the state name for WiFi station
796852
const char * wifiStationGetStateName(uint8_t state)
@@ -1031,6 +1087,29 @@ void wifiWaitNoUsers(NetIndex_t index, uintptr_t parameter, bool debug)
10311087
}
10321088
}
10331089

1090+
//*********************************************************************
1091+
// Determine if any of the WiFi station SSID values are set
1092+
void wifiUpdateSettings()
1093+
{
1094+
bool ssidSet;
1095+
1096+
// Verify that at least one SSID is set
1097+
ssidSet = false;
1098+
for (int index = 0; index < MAX_WIFI_NETWORKS; index++)
1099+
if (strlen(settings.wifiNetworks[index].ssid))
1100+
{
1101+
ssidSet = true;
1102+
break;
1103+
}
1104+
1105+
// Remember the change in SSID values
1106+
wifiStationSsidSet = ssidSet;
1107+
wifiStationRestart = ssidSet;
1108+
1109+
// Determine if the WiFi soft AP SSID string is present
1110+
wifiSoftApSsidSet = (wifiSoftApSsid && strlen(wifiSoftApSsid));
1111+
}
1112+
10341113
//*********************************************************************
10351114
// Verify the WiFi tables
10361115
void wifiVerifyTables()

0 commit comments

Comments
 (0)