esp8266/modnetwork: Rename WLAN keyword args to ssid/security/key.
The WLAN.config() method now supports "ssid", "security" and "key" as aliases to the existing "essid", "authmode" and "password", which are now deprecated. The help text and setup helper are also updated. Addresses issue #8083.
This commit is contained in:
parent
a7c7febe0b
commit
82b8a2d193
@ -37,11 +37,11 @@ const char esp_help_text[] =
|
||||
"import network\n"
|
||||
"sta_if = network.WLAN(network.STA_IF); sta_if.active(True)\n"
|
||||
"sta_if.scan() # Scan for available access points\n"
|
||||
"sta_if.connect(\"<AP_name>\", \"<password>\") # Connect to an AP\n"
|
||||
"sta_if.connect(\"<AP_name>\", \"<key>\") # Connect to an AP\n"
|
||||
"sta_if.isconnected() # Check for successful connection\n"
|
||||
"# Change name/password of ESP8266's AP:\n"
|
||||
"ap_if = network.WLAN(network.AP_IF)\n"
|
||||
"ap_if.config(essid=\"<AP_NAME>\", authmode=network.AUTH_WPA_WPA2_PSK, password=\"<password>\")\n"
|
||||
"ap_if.config(ssid=\"<AP_NAME>\", security=network.AUTH_WPA_WPA2_PSK, key=\"<key>\")\n"
|
||||
"\n"
|
||||
"Control commands:\n"
|
||||
" CTRL-A -- on a blank line, enter raw REPL mode\n"
|
||||
|
@ -109,7 +109,7 @@ STATIC mp_obj_t esp_active(size_t n_args, const mp_obj_t *args) {
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_active_obj, 1, 2, esp_active);
|
||||
|
||||
STATIC mp_obj_t esp_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_ssid, ARG_password, ARG_bssid };
|
||||
enum { ARG_ssid, ARG_key, ARG_bssid };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
||||
{ MP_QSTR_, MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
||||
@ -133,8 +133,8 @@ STATIC mp_obj_t esp_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
|
||||
memcpy(config.ssid, p, len);
|
||||
set_config = true;
|
||||
}
|
||||
if (args[ARG_password].u_obj != mp_const_none) {
|
||||
p = mp_obj_str_get_data(args[ARG_password].u_obj, &len);
|
||||
if (args[ARG_key].u_obj != mp_const_none) {
|
||||
p = mp_obj_str_get_data(args[ARG_key].u_obj, &len);
|
||||
len = MIN(len, sizeof(config.password));
|
||||
memcpy(config.password, p, len);
|
||||
set_config = true;
|
||||
@ -361,6 +361,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
|
||||
wifi_set_macaddr(self->if_id, bufinfo.buf);
|
||||
break;
|
||||
}
|
||||
case MP_QSTR_ssid:
|
||||
case MP_QSTR_essid: {
|
||||
req_if = SOFTAP_IF;
|
||||
size_t len;
|
||||
@ -375,11 +376,13 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
|
||||
cfg.ap.ssid_hidden = mp_obj_is_true(kwargs->table[i].value);
|
||||
break;
|
||||
}
|
||||
case MP_QSTR_security:
|
||||
case MP_QSTR_authmode: {
|
||||
req_if = SOFTAP_IF;
|
||||
cfg.ap.authmode = mp_obj_get_int(kwargs->table[i].value);
|
||||
break;
|
||||
}
|
||||
case MP_QSTR_key:
|
||||
case MP_QSTR_password: {
|
||||
req_if = SOFTAP_IF;
|
||||
size_t len;
|
||||
@ -437,6 +440,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
|
||||
wifi_get_macaddr(self->if_id, mac);
|
||||
return mp_obj_new_bytes(mac, sizeof(mac));
|
||||
}
|
||||
case MP_QSTR_ssid:
|
||||
case MP_QSTR_essid:
|
||||
if (self->if_id == STATION_IF) {
|
||||
val = mp_obj_new_str((char *)cfg.sta.ssid, strlen((char *)cfg.sta.ssid));
|
||||
@ -448,6 +452,7 @@ STATIC mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
|
||||
req_if = SOFTAP_IF;
|
||||
val = mp_obj_new_bool(cfg.ap.ssid_hidden);
|
||||
break;
|
||||
case MP_QSTR_security:
|
||||
case MP_QSTR_authmode:
|
||||
req_if = SOFTAP_IF;
|
||||
val = MP_OBJ_NEW_SMALL_INT(cfg.ap.authmode);
|
||||
|
@ -7,8 +7,8 @@ def wifi():
|
||||
import ubinascii
|
||||
|
||||
ap_if = network.WLAN(network.AP_IF)
|
||||
essid = b"MicroPython-%s" % ubinascii.hexlify(ap_if.config("mac")[-3:])
|
||||
ap_if.config(essid=essid, authmode=network.AUTH_WPA_WPA2_PSK, password=b"micropythoN")
|
||||
ssid = b"MicroPython-%s" % ubinascii.hexlify(ap_if.config("mac")[-3:])
|
||||
ap_if.config(ssid=ssid, security=network.AUTH_WPA_WPA2_PSK, key=b"micropythoN")
|
||||
|
||||
|
||||
def check_bootsec():
|
||||
|
Loading…
x
Reference in New Issue
Block a user