-->
Page 1 of 2

Number of WiFi clients

PostPosted: Fri Feb 26, 2016 3:53 am
by vanjo9800
Hello, I am doing a project in which I need to count the connected WiFi clients, not the ones with TCP. That is why I need to somehow have the number of clients connected to WiFi. Also I need to ban a client to connect if there is a number of clients already connected. Do someone knows how to achieve that actions? Thank you in advance!!!

Re: Number of WiFi clients

PostPosted: Fri Feb 26, 2016 4:31 am
by piersfinlayson
The SDK has the following function which sounds like it'll give you the count of connected APs:

Code: Select alluint8 wifi_softap_get_station_num(void)


Alternatively you could register a callback and get notified every time a station connects and disconnects using:

Code: Select allvoid wifi_set_event_handler_cb(wifi_event_handler_cb_t cb)


The SDK has a good example of using this latter function, and how to retrieve info about the station when it connects/disconnects.

I can't see an obvious way to ban a client from connecting if you've hit a max number. You could disable the DHCP server when a max has been reached - but this would also prevent existing stations from renewing their leases.

Edit: maximum number of stations is configurable in softap_config (max_connection). So use:

Code: Select allbool wifi_softap_set_config(_current)(struct softap_config *config)

Re: Number of WiFi clients

PostPosted: Fri Feb 26, 2016 11:35 am
by vanjo9800
Hello thank you very much for your help, the things you gave me do exactly what I wanted to do.

However, I have some questions about all of them:

1) the wifi_softap_get_station_num() displays the number of devices connected, but sometimes when I disconnect the device the ESP counts it still as connected and after plenty of minutes(around 10) stops counting it. How this can be fixed?

2) for the restriction of max_connections, I changed the parameter in my library to 1:
Code: Select all    struct softap_config conf;
    wifi_softap_get_config(&conf);
    strcpy(reinterpret_cast<char*>(conf.ssid), ssid);
    conf.channel = channel;
    conf.ssid_len = strlen(ssid);
    conf.ssid_hidden = ssid_hidden;
    conf.max_connection = 1;
    conf.beacon_interval = 100;

However, it still does not work because I can connect from 2 devices. What am I doing wrong?

3) for the event listener can you give me an example how to use it because in the SDK in Github I did not find any :)

Thank you very much for your help!!!

Re: Number of WiFi clients

PostPosted: Fri Feb 26, 2016 11:51 am
by martinayotte
Personally, I faced such issue with wifi_softap_get_station_num(), I don't think it is reliable.
So, instead, I've use to count it myself using wifi_softap_get_station_info(); enumeration.