File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -367,7 +367,7 @@ bool WiFiSTAClass::reconnect()
367367 * @param eraseap `true` to erase the AP configuration from the NVS memory.
368368 * @return `true` when successful.
369369 */
370- bool WiFiSTAClass::disconnect (bool wifioff, bool eraseap)
370+ bool WiFiSTAClass::disconnectAsync (bool wifioff, bool eraseap)
371371{
372372 wifi_config_t conf;
373373 wifi_sta_config (&conf);
@@ -391,6 +391,31 @@ bool WiFiSTAClass::disconnect(bool wifioff, bool eraseap)
391391 return false ;
392392}
393393
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+ const unsigned long start = millis ();
410+ while ((WiFiGenericClass::getStatusBits () & STA_CONNECTED_BIT) != 0 ) {
411+ if ((millis () - start) >= timeoutLength){
412+ return false ;
413+ }
414+ delay (2 );
415+ }
416+ return true ;
417+ }
418+
394419/* *
395420 * @brief Reset WiFi settings in NVS to default values.
396421 * @return true if erase succeeded
Original file line number Diff line number Diff line change @@ -61,7 +61,8 @@ class WiFiSTAClass
6161 bool bandwidth (wifi_bandwidth_t bandwidth);
6262
6363 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 = 100 );
6566 bool eraseAP (void );
6667
6768 bool isConnected ();
You can’t perform that action at this time.
0 commit comments