From ea11c88a0982c48b51f7294a2b7eab5a2b8530e8 Mon Sep 17 00:00:00 2001 From: Krzysiek S Date: Fri, 16 Dec 2022 14:22:26 +0100 Subject: [PATCH] Optimize disconnect method in WiFiSTA class (#8760) --- libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp | 27 ++++++++++---------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp index e73fc81987..a6e4d1493b 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp @@ -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. @@ -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); }