@@ -381,6 +381,9 @@ static int wifiFailedConnectionAttempts = 0; // Count the number of connection a
381
381
static bool wifiReconnectRequest; // Set true to request WiFi reconnection
382
382
383
383
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
384
387
385
388
// Start timeout
386
389
static uint32_t wifiStartTimeout;
@@ -435,11 +438,13 @@ void menuWiFi()
435
438
// If we are modifying the SSID table, force restart of WiFi
436
439
wifiRestartRequested = true ;
437
440
wifiFailedConnectionAttempts = 0 ;
441
+ wifiUpdateSettings ();
438
442
}
439
443
else if (incoming == ' a' )
440
444
{
441
445
settings.wifiConfigOverAP ^= 1 ;
442
446
wifiRestartRequested = true ;
447
+ wifiUpdateSettings ();
443
448
}
444
449
else if (incoming == ' c' )
445
450
{
@@ -791,6 +796,57 @@ void wifiStartThrottled(NetIndex_t index, uintptr_t parameter, bool debug)
791
796
networkSequenceNextEntry (NETWORK_WIFI_STATION, debug);
792
797
}
793
798
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
+
794
850
// *********************************************************************
795
851
// Get the state name for WiFi station
796
852
const char * wifiStationGetStateName (uint8_t state)
@@ -1031,6 +1087,29 @@ void wifiWaitNoUsers(NetIndex_t index, uintptr_t parameter, bool debug)
1031
1087
}
1032
1088
}
1033
1089
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
+
1034
1113
// *********************************************************************
1035
1114
// Verify the WiFi tables
1036
1115
void wifiVerifyTables ()
0 commit comments