From df4f236f2c9263dc6e492da325b1f63f26968439 Mon Sep 17 00:00:00 2001 From: Krzysiek S Date: Thu, 15 Dec 2022 22:59:58 +0100 Subject: [PATCH] Optimize disconnect method in WiFiSTA class --- 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); }