Skip to content

Commit

Permalink
Optimize disconnect method in WiFiSTA class (esp8266#8760)
Browse files Browse the repository at this point in the history
  • Loading branch information
cziter15 authored and hasenradball committed Nov 18, 2024
1 parent 83e705d commit ea11c88
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,23 @@ bool ESP8266WiFiSTAClass::disconnect(bool wifioff) {
bool ESP8266WiFiSTAClass::disconnect(bool wifioff, bool eraseCredentials) {
bool ret = false;

// Read current config.
struct station_config conf;
wifi_station_get_config(&conf);

if (eraseCredentials) {
// Read current config.
struct station_config conf;
wifi_station_get_config(&conf);

// Erase credentials.
memset(&conf.ssid, 0, sizeof(conf.ssid));
memset(&conf.password, 0, sizeof(conf.password));

// Store modiffied config.
ETS_UART_INTR_DISABLE();
if(WiFi._persistent) {
wifi_station_set_config(&conf);
} else {
wifi_station_set_config_current(&conf);
}
ETS_UART_INTR_ENABLE();
}

// API Reference: wifi_station_disconnect() need to be called after system initializes and the ESP8266 Station mode is enabled.
Expand All @@ -386,15 +396,6 @@ bool ESP8266WiFiSTAClass::disconnect(bool wifioff, bool eraseCredentials) {
else
ret = true;

ETS_UART_INTR_DISABLE();
if(WiFi._persistent) {
wifi_station_set_config(&conf);
} else {
wifi_station_set_config_current(&conf);
}

ETS_UART_INTR_ENABLE();

if(wifioff) {
WiFi.enableSTA(false);
}
Expand Down

0 comments on commit ea11c88

Please sign in to comment.