diff options
author | Angus Gratton <angus@redyak.com.au> | 2024-11-13 18:14:47 +1100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2024-11-20 14:21:57 +1100 |
commit | f562aa1291ad44605f6b5be75b325a40a208ec41 (patch) | |
tree | 398c0bfcc2638ddcefb06cbfe358e043f0f25fb8 | |
parent | c1b8e65c8e216ce2e90933aef6772de46ad54407 (diff) | |
download | micropython-f562aa1291ad44605f6b5be75b325a40a208ec41.tar.gz micropython-f562aa1291ad44605f6b5be75b325a40a208ec41.zip |
extmod/network_cyw43: Fix isconnected() result on AP interface.
This function is documented to return True if any stations are connected to
the AP. Without this fix it returns True whenever the driver has brought
the AP interface up.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
-rw-r--r-- | extmod/network_cyw43.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/extmod/network_cyw43.c b/extmod/network_cyw43.c index 3066cac75d..891e945de5 100644 --- a/extmod/network_cyw43.c +++ b/extmod/network_cyw43.c @@ -311,7 +311,17 @@ static MP_DEFINE_CONST_FUN_OBJ_1(network_cyw43_disconnect_obj, network_cyw43_dis static mp_obj_t network_cyw43_isconnected(mp_obj_t self_in) { network_cyw43_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_bool(cyw43_tcpip_link_status(self->cyw, self->itf) == 3); + bool result = (cyw43_tcpip_link_status(self->cyw, self->itf) == CYW43_LINK_UP); + + if (result && self->itf == CYW43_ITF_AP) { + // For AP we need to not only know if the link is up, but also if any stations + // have associated. + uint8_t mac_buf[6]; + int num_stas = 1; + cyw43_wifi_ap_get_stas(self->cyw, &num_stas, mac_buf); + result = num_stas > 0; + } + return mp_obj_new_bool(result); } static MP_DEFINE_CONST_FUN_OBJ_1(network_cyw43_isconnected_obj, network_cyw43_isconnected); |