esp8266: Added wlan.isconnected() to maintain parity with other ports.

This commit is contained in:
Bill Owens 2015-06-22 13:22:17 -07:00 committed by Paul Sokolovsky
parent 04fffe6562
commit e2bfa471fa
2 changed files with 14 additions and 0 deletions

View File

@ -105,6 +105,18 @@ STATIC mp_obj_t esp_scan(mp_obj_t cb_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_scan_obj, esp_scan);
/// \method isconnected()
/// Return True if connected to an AP and an IP address has been assigned,
/// false otherwise.
STATIC mp_obj_t esp_isconnected() {
if (wifi_station_get_connect_status() == STATION_GOT_IP) {
return mp_const_true;
}
return mp_const_false;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_isconnected_obj, esp_isconnected);
STATIC const mp_map_elem_t mp_module_network_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_network) },
// MicroPython "network" module interface requires it to contains classes
@ -116,6 +128,7 @@ STATIC const mp_map_elem_t mp_module_network_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_disconnect), (mp_obj_t)&esp_disconnect_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_status), (mp_obj_t)&esp_status_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_scan), (mp_obj_t)&esp_scan_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_isconnected), (mp_obj_t)&esp_isconnected_obj },
#if MODNETWORK_INCLUDE_CONSTANTS
{ MP_OBJ_NEW_QSTR(MP_QSTR_STAT_IDLE),

View File

@ -99,6 +99,7 @@ Q(network)
Q(WLAN)
Q(scan)
Q(status)
Q(isconnected)
Q(STAT_IDLE)
Q(STAT_CONNECTING)
Q(STAT_WRONG_PASSWORD)