Handle number of WiFi client connections
Posted: Tue Nov 20, 2018 1:39 pm
Hi,
I have below method. I keep track of number of WiFi client connections. I run my application both in AP and STA mode. How can I keep track of number of WiFi clients. when last clients gets disconnect. I need to have __num_of_wifi_client == 0.
In AP mode it works fine. but I join another WiFi with STA. Should get called SYSTEM_EVENT_AP_STACONNECTED. If I leave/disconnect from STA. should I get SYSTEM_EVENT_AP_STADISCONNECTED?
Can some one verify. I am getting strange behaviour in STA mode.
I have below method. I keep track of number of WiFi client connections. I run my application both in AP and STA mode. How can I keep track of number of WiFi clients. when last clients gets disconnect. I need to have __num_of_wifi_client == 0.
In AP mode it works fine. but I join another WiFi with STA. Should get called SYSTEM_EVENT_AP_STACONNECTED. If I leave/disconnect from STA. should I get SYSTEM_EVENT_AP_STADISCONNECTED?
Can some one verify. I am getting strange behaviour in STA mode.
Code: Select all
uint32_t __num_of_wifi_client = 0;
esp_err_t wifi_manager_event_handler(void *ctx, system_event_t *event)
{
switch(event->event_id) {
case SYSTEM_EVENT_AP_START:
break;
case SYSTEM_EVENT_AP_STACONNECTED:
__num_of_wifi_client++;
break;
case SYSTEM_EVENT_AP_STADISCONNECTED:
if (__num_of_wifi_client > 0) {
__num_of_wifi_client--;
}
break;
case SYSTEM_EVENT_STA_START:
break;
case SYSTEM_EVENT_STA_GOT_IP:
break;
case SYSTEM_EVENT_STA_DISCONNECTED:
break;
case SYSTEM_EVENT_WIFI_READY:
break;
case SYSTEM_EVENT_STA_STOP:
break;
case SYSTEM_EVENT_STA_CONNECTED:
break;
case SYSTEM_EVENT_STA_LOST_IP:
break;
case SYSTEM_EVENT_SCAN_DONE:
break;
case SYSTEM_EVENT_STA_AUTHMODE_CHANGE:
break;
case SYSTEM_EVENT_AP_STAIPASSIGNED:
break;
default:
break;
}
return ESP_OK;
}