@@ -133,40 +133,40 @@ class Wippersnapper_ESP8266 : public Wippersnapper {
133
133
return false ;
134
134
}
135
135
136
- // Was the network within secrets.json found?
137
- for (int i = 0 ; i < n; ++i) {
138
- if (strcmp (_ssid, WiFi.SSID (i).c_str ()) == 0 ) {
139
- WS_DEBUG_PRINT (" SSID (" );
140
- WS_DEBUG_PRINT (_ssid);
141
- WS_DEBUG_PRINT (" ) found! RSSI: " );
142
- WS_DEBUG_PRINTLN (WiFi.RSSI (i));
143
- return true ;
144
- }
145
- if (WS._isWiFiMulti ) {
136
+ bool foundNetwork = false ;
137
+
138
+ WS_DEBUG_PRINTLN (" WipperSnapper found these WiFi networks:" );
139
+ for (uint8_t i = 0 ; i < n; i++) {
140
+ if (!foundNetwork && strcmp (WiFi.SSID (i).c_str (), _ssid) == 0 ) {
141
+ foundNetwork = true ;
142
+ } else if (!foundNetwork && WS._isWiFiMulti ) {
146
143
// multi network mode
147
144
for (int j = 0 ; j < WS_MAX_ALT_WIFI_NETWORKS; j++) {
148
145
if (strcmp (WS._multiNetworks [j].ssid , WiFi.SSID (i).c_str ()) == 0 ) {
149
- WS_DEBUG_PRINT (" SSID (" );
150
- WS_DEBUG_PRINT (WS._multiNetworks [j].ssid );
151
- WS_DEBUG_PRINT (" ) found! RSSI: " );
152
- WS_DEBUG_PRINTLN (WiFi.RSSI (i));
153
- return true ;
146
+ foundNetwork = true ;
154
147
}
155
148
}
156
149
}
157
- }
158
-
159
- // User-set network not found, print scan results to serial console
160
- WS_DEBUG_PRINTLN (" ERROR: Your requested WiFi network was not found!" );
161
- WS_DEBUG_PRINTLN (" WipperSnapper found these WiFi networks: " );
162
- for (int i = 0 ; i < n; ++i) {
163
150
WS_DEBUG_PRINT (WiFi.SSID (i));
164
- WS_DEBUG_PRINT (" " );
151
+ WS_DEBUG_PRINT (" (" );
152
+ uint8_t BSSID[WL_MAC_ADDR_LENGTH];
153
+ memcpy (BSSID, WiFi.BSSID (i), WL_MAC_ADDR_LENGTH);
154
+ for (int m = 0 ; m < WL_MAC_ADDR_LENGTH; m++) {
155
+ if (m != 0 )
156
+ WS_DEBUG_PRINT (" :" );
157
+ WS_DEBUG_PRINTHEX (BSSID[m]);
158
+ }
159
+ WS_DEBUG_PRINT (" ) " );
165
160
WS_DEBUG_PRINT (WiFi.RSSI (i));
166
- WS_DEBUG_PRINTLN (" dB" );
161
+ WS_DEBUG_PRINT (" dB (ch" );
162
+ WS_DEBUG_PRINT (WiFi.channel (i))
163
+ WS_DEBUG_PRINTLN (" )" );
167
164
}
168
165
169
- return false ;
166
+ if (!foundNetwork) {
167
+ WS_DEBUG_PRINTLN (" ERROR: Your requested WiFi network was not found!" );
168
+ }
169
+ return foundNetwork;
170
170
}
171
171
172
172
/* *******************************************************/
@@ -260,7 +260,6 @@ class Wippersnapper_ESP8266 : public Wippersnapper {
260
260
delay (100 );
261
261
// ESP8266 MUST be in STA mode to avoid device acting as client/server
262
262
WiFi.mode (WIFI_STA);
263
- WiFi.begin (_ssid, _pass);
264
263
_status = WS_NET_DISCONNECTED;
265
264
delay (100 );
266
265
@@ -274,38 +273,28 @@ class Wippersnapper_ESP8266 : public Wippersnapper {
274
273
WS._multiNetworks [i].pass );
275
274
}
276
275
}
277
- // add default network
278
- if (_wifiMulti.existsAP (_ssid) == false ) {
279
- _wifiMulti.addAP (_ssid, _pass);
280
- }
281
- long startRetry = millis ();
282
- WS_DEBUG_PRINTLN (" CONNECTING" );
283
- while (_wifiMulti.run (5000 ) != WL_CONNECTED &&
284
- millis () - startRetry < 10000 ) {
285
- // ESP8266 WDT requires yield() during a busy-loop so it doesn't bite
286
- yield ();
287
- }
288
- if (WiFi.status () == WL_CONNECTED) {
289
- _status = WS_NET_CONNECTED;
290
- } else {
291
- _status = WS_NET_DISCONNECTED;
292
- }
276
+ }
277
+
278
+ // add default network
279
+ if (_wifiMulti.existsAP (_ssid) == false ) {
280
+ _wifiMulti.addAP (_ssid, _pass);
281
+ }
282
+
283
+ long startRetry = millis ();
284
+ WS_DEBUG_PRINTLN (" CONNECTING" );
285
+
286
+ while (_wifiMulti.run (5000 ) != WL_CONNECTED &&
287
+ millis () - startRetry < 10000 ) {
288
+ // ESP8266 WDT requires yield() during a busy-loop so it doesn't bite
289
+ yield ();
290
+ }
291
+
292
+ if (WiFi.status () == WL_CONNECTED) {
293
+ _status = WS_NET_CONNECTED;
293
294
} else {
294
- // single network mode
295
-
296
- // wait for a connection to be established
297
- long startRetry = millis ();
298
- WS_DEBUG_PRINTLN (" CONNECTING" );
299
- while (WiFi.status () != WL_CONNECTED && millis () - startRetry < 10000 ) {
300
- // ESP8266 WDT requires yield() during a busy-loop so it doesn't bite
301
- yield ();
302
- }
303
- if (WiFi.status () == WL_CONNECTED) {
304
- _status = WS_NET_CONNECTED;
305
- } else {
306
- _status = WS_NET_DISCONNECTED;
307
- }
295
+ _status = WS_NET_DISCONNECTED;
308
296
}
297
+
309
298
WS.feedWDT ();
310
299
}
311
300
}
0 commit comments