Skip to content

Commit dbb4aef

Browse files
author
Daniel Campora
committed
cc3200: Make WLAN.isconnected() also work in AP mode.
While in STA mode isconnected() returns True when connected to an AP and the IP has been acquired. In AP mode, WLAN.isconnected() returns True if at least one connected station is present.
1 parent bf4576d commit dbb4aef

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

cc3200/mods/modwlan.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ typedef struct _wlan_obj_t {
9595
uint8_t ssid[33];
9696
uint8_t bssid[6];
9797

98+
uint8_t staconnected;
99+
98100
} wlan_obj_t;
99101

100102
/******************************************************************************
@@ -165,6 +167,7 @@ STATIC wlan_obj_t wlan_obj = {
165167
.ssid = {0},
166168
.bssid = {0},
167169
.mac = {0},
170+
.staconnected = 0
168171
};
169172

170173
STATIC const mp_cb_methods_t wlan_cb_methods;
@@ -225,10 +228,12 @@ void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent) {
225228
}
226229
break;
227230
case SL_WLAN_STA_CONNECTED_EVENT:
228-
// TODO
231+
wlan_obj.staconnected++;
229232
break;
230233
case SL_WLAN_STA_DISCONNECTED_EVENT:
231-
// TODO
234+
if (wlan_obj.staconnected > 0) {
235+
wlan_obj.staconnected--;
236+
}
232237
break;
233238
case SL_WLAN_P2P_DEV_FOUND_EVENT:
234239
// TODO
@@ -380,10 +385,8 @@ void wlan_init0 (void) {
380385
}
381386

382387
void wlan_first_start (void) {
383-
// clear wlan data after checking any of the status flags
384-
wlan_initialize_data();
385-
386388
if (wlan_obj.mode < 0) {
389+
wlan_initialize_data();
387390
wlan_obj.mode = sl_Start(0, 0, 0);
388391
sl_LockObjUnlock (&wlan_LockObj);
389392
}
@@ -540,6 +543,7 @@ STATIC void wlan_initialize_data (void) {
540543
wlan_obj.gateway = 0;
541544
wlan_obj.ip = 0;
542545
wlan_obj.security = SL_SEC_TYPE_OPEN;
546+
wlan_obj.staconnected = 0;
543547
memset(wlan_obj.ssid, 0, sizeof(wlan_obj.ssid));
544548
memset(wlan_obj.bssid, 0, sizeof(wlan_obj.bssid));
545549
}
@@ -548,6 +552,7 @@ STATIC void wlan_reenable (SlWlanMode_t mode) {
548552
// stop and start again
549553
sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER);
550554
sl_Stop(SL_STOP_TIMEOUT);
555+
wlan_initialize_data();
551556
wlan_obj.mode = sl_Start(0, 0, 0);
552557
sl_LockObjUnlock (&wlan_LockObj);
553558
ASSERT (wlan_obj.mode == mode);
@@ -801,10 +806,11 @@ STATIC mp_obj_t wlan_disconnect(mp_obj_t self_in) {
801806
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_disconnect_obj, wlan_disconnect);
802807

803808
/// \method is_connected()
804-
/// Return true if connected to the AP and an IP address has been assigned. False otherwise.
809+
/// Return true if connected to the AP and an IP address has been assigned. Also true if there's any station connected.
810+
/// false otherwise.
805811
STATIC mp_obj_t wlan_isconnected(mp_obj_t self_in) {
806-
if (GET_STATUS_BIT(wlan_obj.status, STATUS_BIT_CONNECTION) &&
807-
GET_STATUS_BIT(wlan_obj.status, STATUS_BIT_IP_ACQUIRED)) {
812+
if ((GET_STATUS_BIT(wlan_obj.status, STATUS_BIT_CONNECTION) &&
813+
GET_STATUS_BIT(wlan_obj.status, STATUS_BIT_IP_ACQUIRED)) || (wlan_obj.staconnected > 0)) {
808814
return mp_const_true;
809815
}
810816
return mp_const_false;

0 commit comments

Comments
 (0)