File tree 4 files changed +17
-7
lines changed
ESP8266AVRISP/examples/Arduino_Wifi_AVRISP
4 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -254,6 +254,7 @@ Function returns one of the following connection statuses:
254
254
- ``WL_CONNECT_FAILED `` if password is incorrect
255
255
- ``WL_IDLE_STATUS `` when Wi-Fi is in process of changing between statuses
256
256
- ``WL_DISCONNECTED `` if module is not configured in station mode
257
+ - ``-1 `` on timeout
257
258
258
259
Configuration
259
260
~~~~~~~~~~~~~
Original file line number Diff line number Diff line change @@ -24,7 +24,10 @@ void setup() {
24
24
25
25
WiFi.mode (WIFI_STA);
26
26
WiFi.begin (ssid, pass);
27
- while (WiFi.waitForConnectResult () != WL_CONNECTED);
27
+ while (WiFi.waitForConnectResult () != WL_CONNECTED) {
28
+ WiFi.begin (ssid, pass);
29
+ Serial.println (" WiFi failed, retrying." );
30
+ }
28
31
29
32
MDNS.begin (host);
30
33
MDNS.addService (" avrisp" , " tcp" , port);
Original file line number Diff line number Diff line change 25
25
#include " ESP8266WiFi.h"
26
26
#include " ESP8266WiFiGeneric.h"
27
27
#include " ESP8266WiFiSTA.h"
28
+ #include " PolledTimeout.h"
28
29
29
30
#include " c_types.h"
30
31
#include " ets_sys.h"
@@ -441,17 +442,22 @@ bool ESP8266WiFiSTAClass::getAutoReconnect() {
441
442
/* *
442
443
* Wait for WiFi connection to reach a result
443
444
* returns the status reached or disconnect if STA is off
444
- * @return wl_status_t
445
+ * @return wl_status_t or -1 on timeout
445
446
*/
446
- uint8_t ESP8266WiFiSTAClass::waitForConnectResult () {
447
+ int8_t ESP8266WiFiSTAClass::waitForConnectResult (unsigned long timeoutLength ) {
447
448
// 1 and 3 have STA enabled
448
449
if ((wifi_get_opmode () & 1 ) == 0 ) {
449
450
return WL_DISCONNECTED;
450
451
}
451
- while (status () == WL_DISCONNECTED) {
452
- delay (100 );
452
+ using esp8266::polledTimeout::oneShot;
453
+ oneShot timeout (timeoutLength); // number of milliseconds to wait before returning timeout error
454
+ while (!timeout) {
455
+ yield ();
456
+ if (status () != WL_DISCONNECTED) {
457
+ return status ();
458
+ }
453
459
}
454
- return status ();
460
+ return - 1 ; // -1 indicates timeout
455
461
}
456
462
457
463
/* *
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ class ESP8266WiFiSTAClass {
57
57
bool setAutoReconnect (bool autoReconnect);
58
58
bool getAutoReconnect ();
59
59
60
- uint8_t waitForConnectResult ();
60
+ int8_t waitForConnectResult (unsigned long timeoutLength = 60000 );
61
61
62
62
// STA network info
63
63
IPAddress localIP ();
You can’t perform that action at this time.
0 commit comments