Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 0c079bd

Browse files
committed
PYFW-317: wlan.isconnected not returning True when station is connected in AP mode Issue #244
1 parent 5a37c29 commit 0c079bd

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

esp32/mods/modwlan.c

+13-2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ static EventGroupHandle_t wifi_event_group;
9898

9999
static bool mod_wlan_is_deinit = false;
100100
static bool mod_wlan_was_sta_disconnected;
101+
static uint16_t mod_wlan_ap_number_of_connections = 0;
101102

102103
/* Variables holding wlan conn params for wakeup recovery of connections */
103104
static uint8_t wlan_conn_recover_ssid[(MODWLAN_SSID_LEN_MAX + 1)];
@@ -371,11 +372,23 @@ STATIC esp_err_t wlan_event_handler(void *ctx, system_event_t *event) {
371372
break;
372373

373374
case SYSTEM_EVENT_AP_START: /**< ESP32 soft-AP start */
375+
mod_wlan_ap_number_of_connections = 0;
374376
wlan_obj.soft_ap_stopped = false;
375377
break;
376378
case SYSTEM_EVENT_AP_STOP: /**< ESP32 soft-AP stop */
379+
xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
377380
wlan_obj.soft_ap_stopped = true;
378381
break;
382+
case SYSTEM_EVENT_AP_STACONNECTED: /**< a station connected to ESP32 soft-AP */
383+
mod_wlan_ap_number_of_connections++;
384+
xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
385+
break;
386+
case SYSTEM_EVENT_AP_STADISCONNECTED: /**< a station disconnected from ESP32 soft-AP */
387+
mod_wlan_ap_number_of_connections--;
388+
if(mod_wlan_ap_number_of_connections == 0) {
389+
xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
390+
}
391+
break;
379392
case SYSTEM_EVENT_WIFI_READY: /**< ESP32 WiFi ready */
380393
case SYSTEM_EVENT_SCAN_DONE: /**< ESP32 finish scanning AP */
381394
case SYSTEM_EVENT_STA_AUTHMODE_CHANGE: /**< the auth mode of AP connected by ESP32 station changed */
@@ -385,8 +398,6 @@ STATIC esp_err_t wlan_event_handler(void *ctx, system_event_t *event) {
385398
case SYSTEM_EVENT_STA_WPS_ER_TIMEOUT: /**< ESP32 station wps timeout in enrollee mode */
386399
case SYSTEM_EVENT_STA_WPS_ER_PIN: /**< ESP32 station wps pin code in enrollee mode */
387400

388-
case SYSTEM_EVENT_AP_STACONNECTED: /**< a station connected to ESP32 soft-AP */
389-
case SYSTEM_EVENT_AP_STADISCONNECTED: /**< a station disconnected from ESP32 soft-AP */
390401
case SYSTEM_EVENT_AP_STAIPASSIGNED: /**< ESP32 soft-AP assign an IP to a connected station */
391402
case SYSTEM_EVENT_AP_PROBEREQRECVED: /**< Receive probe request packet in soft-AP interface */
392403
case SYSTEM_EVENT_GOT_IP6: /**< ESP32 station or ap or ethernet interface v6IP addr is preferred */

0 commit comments

Comments
 (0)