Skip to content

Commit e2bfa47

Browse files
owens-billpfalcon
authored andcommitted
esp8266: Added wlan.isconnected() to maintain parity with other ports.
1 parent 04fffe6 commit e2bfa47

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

esp8266/modnetwork.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@ STATIC mp_obj_t esp_scan(mp_obj_t cb_in) {
105105
}
106106
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_scan_obj, esp_scan);
107107

108+
/// \method isconnected()
109+
/// Return True if connected to an AP and an IP address has been assigned,
110+
/// false otherwise.
111+
STATIC mp_obj_t esp_isconnected() {
112+
if (wifi_station_get_connect_status() == STATION_GOT_IP) {
113+
return mp_const_true;
114+
}
115+
return mp_const_false;
116+
}
117+
118+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_isconnected_obj, esp_isconnected);
119+
108120
STATIC const mp_map_elem_t mp_module_network_globals_table[] = {
109121
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_network) },
110122
// MicroPython "network" module interface requires it to contains classes
@@ -116,6 +128,7 @@ STATIC const mp_map_elem_t mp_module_network_globals_table[] = {
116128
{ MP_OBJ_NEW_QSTR(MP_QSTR_disconnect), (mp_obj_t)&esp_disconnect_obj },
117129
{ MP_OBJ_NEW_QSTR(MP_QSTR_status), (mp_obj_t)&esp_status_obj },
118130
{ MP_OBJ_NEW_QSTR(MP_QSTR_scan), (mp_obj_t)&esp_scan_obj },
131+
{ MP_OBJ_NEW_QSTR(MP_QSTR_isconnected), (mp_obj_t)&esp_isconnected_obj },
119132

120133
#if MODNETWORK_INCLUDE_CONSTANTS
121134
{ MP_OBJ_NEW_QSTR(MP_QSTR_STAT_IDLE),

esp8266/qstrdefsport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ Q(network)
9999
Q(WLAN)
100100
Q(scan)
101101
Q(status)
102+
Q(isconnected)
102103
Q(STAT_IDLE)
103104
Q(STAT_CONNECTING)
104105
Q(STAT_WRONG_PASSWORD)

0 commit comments

Comments
 (0)