diff options
author | puuu <puuu@users.noreply.github.com> | 2016-10-12 10:08:40 +0900 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-11-01 06:59:41 +0300 |
commit | b97c17e125b9eaf5dfa9a5d540175377c79e34fd (patch) | |
tree | 451a9a59eae589dfe3b9f39f94347b5f57384afa | |
parent | eddcf0a5de7a1fe73ccf5c9e85b57aaf9c527bad (diff) | |
download | micropython-b97c17e125b9eaf5dfa9a5d540175377c79e34fd.tar.gz micropython-b97c17e125b9eaf5dfa9a5d540175377c79e34fd.zip |
esp8266/modnetwork.c: Allows AP reconnection without WiFi credentials
There is no automatic reconnect after wlan.active(False);
wlan.active(True). This commit provide the possibility to run
wlan.connect() without parameter, to reconnect to the previously
connected AP.
resolve #2493
-rw-r--r-- | esp8266/modnetwork.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/esp8266/modnetwork.c b/esp8266/modnetwork.c index ed828e5844..a48edcfa2d 100644 --- a/esp8266/modnetwork.c +++ b/esp8266/modnetwork.c @@ -100,17 +100,23 @@ STATIC mp_obj_t esp_connect(mp_uint_t n_args, const mp_obj_t *args) { mp_uint_t len; const char *p; - p = mp_obj_str_get_data(args[1], &len); - memcpy(config.ssid, p, len); - p = mp_obj_str_get_data(args[2], &len); - memcpy(config.password, p, len); + if (n_args > 1) { + p = mp_obj_str_get_data(args[1], &len); + memcpy(config.ssid, p, len); + if (n_args > 2) { + p = mp_obj_str_get_data(args[2], &len); + } else { + p = ""; + } + memcpy(config.password, p, len); - error_check(wifi_station_set_config(&config), "Cannot set STA config"); + error_check(wifi_station_set_config(&config), "Cannot set STA config"); + } error_check(wifi_station_connect(), "Cannot connect to AP"); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_connect_obj, 3, 7, esp_connect); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_connect_obj, 1, 7, esp_connect); STATIC mp_obj_t esp_disconnect(mp_obj_t self_in) { require_if(self_in, STATION_IF); |