@@ -98,6 +98,7 @@ static EventGroupHandle_t wifi_event_group;
98
98
99
99
static bool mod_wlan_is_deinit = false;
100
100
static bool mod_wlan_was_sta_disconnected ;
101
+ static uint16_t mod_wlan_ap_number_of_connections = 0 ;
101
102
102
103
/* Variables holding wlan conn params for wakeup recovery of connections */
103
104
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) {
371
372
break ;
372
373
373
374
case SYSTEM_EVENT_AP_START : /**< ESP32 soft-AP start */
375
+ mod_wlan_ap_number_of_connections = 0 ;
374
376
wlan_obj .soft_ap_stopped = false;
375
377
break ;
376
378
case SYSTEM_EVENT_AP_STOP : /**< ESP32 soft-AP stop */
379
+ xEventGroupClearBits (wifi_event_group , CONNECTED_BIT );
377
380
wlan_obj .soft_ap_stopped = true;
378
381
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 ;
379
392
case SYSTEM_EVENT_WIFI_READY : /**< ESP32 WiFi ready */
380
393
case SYSTEM_EVENT_SCAN_DONE : /**< ESP32 finish scanning AP */
381
394
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) {
385
398
case SYSTEM_EVENT_STA_WPS_ER_TIMEOUT : /**< ESP32 station wps timeout in enrollee mode */
386
399
case SYSTEM_EVENT_STA_WPS_ER_PIN : /**< ESP32 station wps pin code in enrollee mode */
387
400
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 */
390
401
case SYSTEM_EVENT_AP_STAIPASSIGNED : /**< ESP32 soft-AP assign an IP to a connected station */
391
402
case SYSTEM_EVENT_AP_PROBEREQRECVED : /**< Receive probe request packet in soft-AP interface */
392
403
case SYSTEM_EVENT_GOT_IP6 : /**< ESP32 station or ap or ethernet interface v6IP addr is preferred */
0 commit comments