Skip to content

Commit

Permalink
WiFi.disconnect() "aligned with Aduino.cc". waiting for status change.
Browse files Browse the repository at this point in the history
WiFi.disconnect renamed to disconnectAsync

new WiFi.disconnect waits for status change
  • Loading branch information
JAndrassy committed Jan 3, 2024
1 parent b2e7338 commit 1c6cbf3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
21 changes: 20 additions & 1 deletion libraries/WiFi/src/WiFiSTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ bool WiFiSTAClass::reconnect()
* @param eraseap `true` to erase the AP configuration from the NVS memory.
* @return `true` when successful.
*/
bool WiFiSTAClass::disconnect(bool wifioff, bool eraseap)
bool WiFiSTAClass::disconnectAsync(bool wifioff, bool eraseap)
{
wifi_config_t conf;
wifi_sta_config(&conf);
Expand All @@ -391,6 +391,25 @@ bool WiFiSTAClass::disconnect(bool wifioff, bool eraseap)
return false;
}

/**
* Disconnect from the network.
* @param wifioff `true` to turn the Wi-Fi radio off.
* @param eraseap `true` to erase the AP configuration from the NVS memory.
* @param timeoutLength timeout to wait for status change
* @return `true` when successful.
*/
bool WiFiSTAClass::disconnect(bool wifioff, bool eraseap, unsigned long timeoutLength)
{
bool rv = disconnectAsync(wifioff, eraseap);
if (!rv)
return false;
unsigned long start = millis();
while (status() == WL_CONNECTED && (millis() - start) < timeoutLength) {
delay(100);
}
return status() != WL_CONNECTED;
}

/**
* @brief Reset WiFi settings in NVS to default values.
* @return true if erase succeeded
Expand Down
3 changes: 2 additions & 1 deletion libraries/WiFi/src/WiFiSTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class WiFiSTAClass
bool bandwidth(wifi_bandwidth_t bandwidth);

bool reconnect();
bool disconnect(bool wifioff = false, bool eraseap = false);
bool disconnectAsync(bool wifioff = false, bool eraseap = false);
bool disconnect(bool wifioff = false, bool eraseap = false, unsigned long timeoutLength = 3000);
bool eraseAP(void);

bool isConnected();
Expand Down

0 comments on commit 1c6cbf3

Please sign in to comment.