File tree 2 files changed +28
-2
lines changed
2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -367,7 +367,7 @@ bool WiFiSTAClass::reconnect()
367
367
* @param eraseap `true` to erase the AP configuration from the NVS memory.
368
368
* @return `true` when successful.
369
369
*/
370
- bool WiFiSTAClass::disconnect (bool wifioff, bool eraseap)
370
+ bool WiFiSTAClass::disconnectAsync (bool wifioff, bool eraseap)
371
371
{
372
372
wifi_config_t conf;
373
373
wifi_sta_config (&conf);
@@ -391,6 +391,31 @@ bool WiFiSTAClass::disconnect(bool wifioff, bool eraseap)
391
391
return false ;
392
392
}
393
393
394
+ /* *
395
+ * Disconnect from the network.
396
+ * @param wifioff `true` to turn the Wi-Fi radio off.
397
+ * @param eraseap `true` to erase the AP configuration from the NVS memory.
398
+ * @param timeoutLength timeout to wait for status change
399
+ * @return `true` when successful.
400
+ */
401
+ bool WiFiSTAClass::disconnect (bool wifioff, bool eraseap, unsigned long timeoutLength)
402
+ {
403
+ if (!disconnectAsync (wifioff, eraseap)) {
404
+ return false ;
405
+ }
406
+ if (!timeoutLength) {
407
+ return true ;
408
+ }
409
+ unsigned long start = millis ();
410
+ while ((WiFiGenericClass::getStatusBits () & STA_CONNECTED_BIT) != 0 ) {
411
+ if ((millis () - start) >= timeoutLength){
412
+ return false ;
413
+ }
414
+ delay (1 );
415
+ }
416
+ return true ;
417
+ }
418
+
394
419
/* *
395
420
* @brief Reset WiFi settings in NVS to default values.
396
421
* @return true if erase succeeded
Original file line number Diff line number Diff line change @@ -61,7 +61,8 @@ class WiFiSTAClass
61
61
bool bandwidth (wifi_bandwidth_t bandwidth);
62
62
63
63
bool reconnect ();
64
- bool disconnect (bool wifioff = false , bool eraseap = false );
64
+ bool disconnectAsync (bool wifioff = false , bool eraseap = false );
65
+ bool disconnect (bool wifioff = false , bool eraseap = false , unsigned long timeoutLength = 3000 );
65
66
bool eraseAP (void );
66
67
67
68
bool isConnected ();
You can’t perform that action at this time.
0 commit comments