@@ -77,39 +77,95 @@ static void ICACHE_FLASH_ATTR setLed(int on) {
77
77
#endif
78
78
}
79
79
80
- static uint8_t ledState = 0 ;
80
+ /*
81
+
82
+ Five States of Wireless System
83
+
84
+ In the description, bold is the wireless mode, small text indicates connectivity or lack
85
+ thereof, and after hyphen (-) indicates LED behavior and the timing I used in the video
86
+ below.
87
+
88
+ STA (no IP address) [Not wirelessly accessible] - OFF constantly
89
+ STA (has IP address) [Wirelessly accessible] - OFF 4000 ms, ON 25 ms
90
+ AP (has IP address) [Wirelessly accessible]* - ON constantly
91
+ STA+AP (no IP on STA, IP on AP) [Wirelessly accessible]* - OFF 2000 ms, ON 2000 ms
92
+ STA+AP (has IP on STA and AP) [Wirelessly accessible]* - OFF 2000 ms, ON 25 ms,
93
+ OFF 150 ms, ON 2000 ms
94
+
95
+ *In AP mode, there is always an IP address associated with the module because it itself
96
+ is serving as the gateway.
97
+
98
+ */
99
+
100
+ static uint8_t ledPhase = 0 ;
81
101
82
102
// Timer callback to update the LED
83
103
static void ICACHE_FLASH_ATTR ledTimerCb (void * v ) {
84
- int time = 1000 ;
85
-
86
- if (wifiState == wifiGotIP ) {
87
- // connected, all is good, solid light with a short dark blip every 3 seconds
88
- ledState = 1 - ledState ;
89
- time = ledState ? 2900 : 100 ;
90
- } else if (wifiState == wifiIsConnected ) {
91
- // waiting for DHCP, go on/off every second
92
- ledState = 1 - ledState ;
93
- time = 1000 ;
94
- } else {
95
- // not connected
104
+ int state = 0 ;
105
+ int time = 1000 ;
106
+
96
107
switch (wifi_get_opmode ()) {
97
- case 1 : // STA
98
- ledState = 0 ;
99
- break ;
100
- case 2 : // AP
101
- ledState = 1 - ledState ;
102
- time = ledState ? 50 : 1950 ;
103
- break ;
104
- case 3 : // STA+AP
105
- ledState = 1 - ledState ;
106
- time = ledState ? 50 : 950 ;
107
- break ;
108
+ case STATION_MODE :
109
+ switch (ledPhase ) {
110
+ case 0 :
111
+ case 2 :
112
+ state = 0 ;
113
+ time = 4000 ;
114
+ break ;
115
+ case 1 :
116
+ case 3 :
117
+ if (wifiState == wifiGotIP )
118
+ state = 1 ;
119
+ else
120
+ state = 0 ;
121
+ time = 25 ;
122
+ break ;
123
+ }
124
+ break ;
125
+ case SOFTAP_MODE :
126
+ state = 1 ;
127
+ time = 2000 ;
128
+ break ;
129
+ case STATIONAP_MODE :
130
+ if (wifiState == wifiGotIP ) {
131
+ switch (ledPhase ) {
132
+ case 0 :
133
+ state = 0 ;
134
+ time = 2000 ;
135
+ break ;
136
+ case 1 :
137
+ state = 1 ;
138
+ time = 25 ;
139
+ break ;
140
+ case 2 :
141
+ state = 0 ;
142
+ time = 150 ;
143
+ break ;
144
+ case 3 :
145
+ state = 1 ;
146
+ time = 2000 ;
147
+ break ;
148
+ }
149
+ }
150
+ else {
151
+ switch (ledPhase ) {
152
+ case 0 :
153
+ case 2 :
154
+ state = 0 ;
155
+ break ;
156
+ case 1 :
157
+ case 3 :
158
+ state = 1 ;
159
+ break ;
160
+ }
161
+ time = 2000 ;
162
+ }
163
+ break ;
108
164
}
109
- }
110
165
111
- setLed (ledState );
112
- os_timer_arm (& ledTimer , time , 0 );
166
+ setLed (state );
167
+ ledPhase = (ledPhase + 1 ) % 4 ;
168
+ os_timer_arm (& ledTimer , time , 0 );
113
169
}
114
170
115
171
// change the wifi state indication
0 commit comments