@@ -30,6 +30,30 @@ static const char * wifiAuthorizationName[] =
30
30
static const int wifiAuthorizationNameEntries =
31
31
sizeof (wifiAuthorizationName) / sizeof (wifiAuthorizationName[0 ]);
32
32
33
+ enum WIFI_STATION_STATES
34
+ {
35
+ WIFI_STATION_STATE_OFF,
36
+ WIFI_STATION_STATE_WAIT_NO_USERS,
37
+ WIFI_STATION_STATE_RESTART,
38
+ WIFI_STATION_STATE_STARTING,
39
+ WIFI_STATION_STATE_ONLINE,
40
+ WIFI_STATION_STATE_STABLE,
41
+ // The following line must be the last in the list
42
+ WIFI_STATION_STATE_MAX
43
+ };
44
+ uint8_t wifiStationState;
45
+
46
+ const char * wifiStationStateName[] =
47
+ {
48
+ " WIFI_STATION_STATE_OFF" ,
49
+ " WIFI_STATION_STATE_WAIT_NO_USERS" ,
50
+ " WIFI_STATION_STATE_RESTART" ,
51
+ " WIFI_STATION_STATE_STARTING" ,
52
+ " WIFI_STATION_STATE_ONLINE" ,
53
+ " WIFI_STATION_STATE_STABLE" ,
54
+ };
55
+ const int wifiStationStateNameEntries = sizeof (wifiStationStateName) / sizeof (wifiStationStateName[0 ]);
56
+
33
57
// ----------------------------------------------------------------------
34
58
// ESP-NOW bringup from example 4_9_ESP_NOW
35
59
// 1. Set station mode
@@ -767,6 +791,15 @@ void wifiStartThrottled(NetIndex_t index, uintptr_t parameter, bool debug)
767
791
networkSequenceNextEntry (NETWORK_WIFI_STATION, debug);
768
792
}
769
793
794
+ // *********************************************************************
795
+ // Get the state name for WiFi station
796
+ const char * wifiStationGetStateName (uint8_t state)
797
+ {
798
+ if (state < wifiStationStateNameEntries)
799
+ return wifiStationStateName[state];
800
+ return " Unknown WiFi Station state" ;
801
+ }
802
+
770
803
// *********************************************************************
771
804
// Stop the WiFi station
772
805
// Inputs:
@@ -807,6 +840,44 @@ bool wifiStationOn(const char * fileName, uint32_t lineNumber)
807
840
__FILE__, __LINE__);
808
841
}
809
842
843
+ // *********************************************************************
844
+ // Set the WiFi station state
845
+ void wifiStationSetState (uint8_t newState)
846
+ {
847
+ // Display the state transition
848
+ if (settings.debugWifiState )
849
+ {
850
+ const char * asterisk;
851
+ const char * stateNew;
852
+ const char * stateOld;
853
+ const char * transition;
854
+
855
+ // Get the current state name
856
+ stateOld = wifiStationGetStateName (wifiStationState);
857
+
858
+ // Check for a transition
859
+ if (newState != wifiStationState)
860
+ {
861
+ asterisk = " " ;
862
+ transition = " --> " ;
863
+ stateNew = wifiStationGetStateName (newState);
864
+ }
865
+ else
866
+ {
867
+ // No transition
868
+ asterisk = " *" ;
869
+ transition = " " ;
870
+ stateNew = " " ;
871
+ }
872
+
873
+ // Display the state transition
874
+ systemPrintf (" %s%s%s%s\r\n " , asterisk, stateOld, transition, stateNew);
875
+ }
876
+
877
+ // Set the new state
878
+ wifiStationState = newState;
879
+ }
880
+
810
881
// *********************************************************************
811
882
// Handle WiFi station reconnection requests
812
883
bool wifiStationReconnectionRequest ()
@@ -966,6 +1037,13 @@ void wifiVerifyTables()
966
1037
{
967
1038
// Verify the RTK_WIFI tables
968
1039
wifi.verifyTables ();
1040
+
1041
+ // Verify the WiFi station state name table
1042
+ if (WIFI_STATION_STATE_MAX != wifiStationStateNameEntries)
1043
+ {
1044
+ systemPrintf (" ERROR: Fix wifiStationStateName list to match WIFI_STATION_STATES!\r\n " );
1045
+ reportFatalError (" Fix wifiStationStateName list to match WIFI_STATION_STATES!" );
1046
+ }
969
1047
}
970
1048
971
1049
// *********************************************************************
0 commit comments