Skip to content

Commit d3c8d27

Browse files
authored
Add eraseap option to WiFi disconnect method. (#8758)
Add eraseCredentials option to WiFi disconnect method (legacy default: true)
1 parent 64077df commit d3c8d27

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,15 +353,32 @@ bool ESP8266WiFiSTAClass::reconnect() {
353353
}
354354

355355
/**
356-
* Disconnect from the network
357-
* @param wifioff
356+
* Disconnect from the network with clearing saved credentials
357+
* @param wifioff Bool indicating whether STA should be disabled.
358358
* @return one value of wl_status_t enum
359359
*/
360360
bool ESP8266WiFiSTAClass::disconnect(bool wifioff) {
361+
// Disconnect with clearing saved credentials.
362+
return disconnect(wifioff, true);
363+
}
364+
365+
/**
366+
* Disconnect from the network
367+
* @param wifioff Bool indicating whether STA should be disabled.
368+
* @param eraseCredentials Bool indicating whether saved credentials should be erased.
369+
* @return one value of wl_status_t enum
370+
*/
371+
bool ESP8266WiFiSTAClass::disconnect(bool wifioff, bool eraseCredentials) {
361372
bool ret = false;
373+
374+
// Read current config.
362375
struct station_config conf;
363-
*conf.ssid = 0;
364-
*conf.password = 0;
376+
wifi_station_get_config(&conf);
377+
378+
if (eraseCredentials) {
379+
memset(&conf.ssid, 0, sizeof(conf.ssid));
380+
memset(&conf.password, 0, sizeof(conf.password));
381+
}
365382

366383
// API Reference: wifi_station_disconnect() need to be called after system initializes and the ESP8266 Station mode is enabled.
367384
if (WiFi.getMode() & WIFI_STA)

libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ class ESP8266WiFiSTAClass: public LwipIntf {
4848
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000);
4949

5050
bool reconnect();
51+
5152
bool disconnect(bool wifioff = false);
53+
bool disconnect(bool wifioff, bool eraseCredentials);
5254

5355
bool isConnected();
5456

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy