Skip to content

Unify WiFiSTA disconnect with ESP32 Arduino core. #8756

New issue

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

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

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
41 changes: 17 additions & 24 deletions libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -46,6 +44,9 @@ extern "C" {

#include "debug.h"

extern "C" void esp_schedule();
extern "C" void esp_yield();

// -----------------------------------------------------------------------------------------------------------------------
// ---------------------------------------------------- Private functions ------------------------------------------------
// -----------------------------------------------------------------------------------------------------------------------
Expand All @@ -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");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down