diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp
index 4a5d4d963f..be9529175a 100644
--- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp
+++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp
@@ -28,8 +28,6 @@
 #include "PolledTimeout.h"
 #include "LwipIntf.h"
 
-#include <coredecls.h>
-
 #include "c_types.h"
 #include "ets_sys.h"
 #include "os_type.h"
@@ -46,6 +44,9 @@ extern "C" {
 
 #include "debug.h"
 
+extern "C" void esp_schedule();
+extern "C" void esp_yield();
+
 // -----------------------------------------------------------------------------------------------------------------------
 // ---------------------------------------------------- Private functions ------------------------------------------------
 // -----------------------------------------------------------------------------------------------------------------------
@@ -61,7 +62,7 @@ static bool sta_config_equal(const station_config& lhs, const station_config& rh
  */
 static bool sta_config_equal(const station_config& lhs, const station_config& rhs) {
 
-#if (NONOSDK >= (0x30000 - 1))
+#ifdef NONOSDK3V0
     static_assert(sizeof(station_config) == 116, "struct station_config has changed, please update comparison function");
 #else
     static_assert(sizeof(station_config) == 112, "struct station_config has changed, please update comparison function");
@@ -94,18 +95,8 @@ static bool sta_config_equal(const station_config& lhs, const station_config& rh
         return false;
     }
 
-#if (NONOSDK >= (0x30000 - 1))
-    if(lhs.open_and_wep_mode_disable != rhs.open_and_wep_mode_disable) {
-        return false;
-    }
-#endif
-
-#if (NONOSDK >= (0x30200))
-    if(lhs.channel != rhs.channel) {
-        return false;
-    }
-
-    if(lhs.all_channel_scan != rhs.all_channel_scan) {
+#ifdef NONOSDK3V0
+    if (lhs.open_and_wep_mode_disable != rhs.open_and_wep_mode_disable) {
         return false;
     }
 #endif
@@ -145,7 +136,7 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase,
     int passphraseLen = passphrase == nullptr ? 0 : strlen(passphrase);
     if(passphraseLen > 64) {
         // fail passphrase too long!
-        return WL_WRONG_PASSWORD;
+        return WL_CONNECT_FAILED;
     }
 
     struct station_config conf;
@@ -166,13 +157,9 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase,
     }
 
     conf.threshold.rssi = -127;
-#if (NONOSDK >= (0x30000 - 1))
+#ifdef NONOSDK3V0
     conf.open_and_wep_mode_disable = !(_useInsecureWEP || *conf.password == 0);
 #endif
-#if (NONOSDK >= (0x30200))
-    conf.channel = channel;
-    conf.all_channel_scan = true;
-#endif
 
     if(bssid) {
         conf.bssid_set = 1;
@@ -357,11 +344,17 @@ bool ESP8266WiFiSTAClass::reconnect() {
  * @param wifioff
  * @return  one value of wl_status_t enum
  */
-bool ESP8266WiFiSTAClass::disconnect(bool wifioff) {
+bool ESP8266WiFiSTAClass::disconnect(bool wifioff, bool eraseap) {
     bool ret = false;
+    
+    // Read current config.
     struct station_config conf;
-    *conf.ssid = 0;
-    *conf.password = 0;
+    wifi_station_get_config(&conf);
+
+    if (eraseap) {
+        memset(&conf.ssid, 0, sizeof(conf.ssid));
+        memset(&conf.password, 0, sizeof(conf.password));
+    };
 
     // API Reference: wifi_station_disconnect() need to be called after system initializes and the ESP8266 Station mode is enabled.
     if (WiFi.getMode() & WIFI_STA)
diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h
index 32813a5377..b607b8849e 100644
--- a/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h
+++ b/libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h
@@ -48,7 +48,7 @@ class ESP8266WiFiSTAClass: public LwipIntf {
         bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000);
 
         bool reconnect();
-        bool disconnect(bool wifioff = false);
+        bool disconnect(bool wifioff = false, bool eraseap = false);
 
         bool isConnected();