Skip to content

Commit 5212b0d

Browse files
cziter15hasenradball
authored andcommitted
Add eraseap option to WiFi disconnect method. (esp8266#8758)
Add eraseCredentials option to WiFi disconnect method (legacy default: true)
1 parent cce5267 commit 5212b0d

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp

+21-4
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

+2
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)