Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Optimize disconnect method in WiFiSTA class #8760

Merged
merged 3 commits into from
Dec 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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