Page 1 of 1

wifi_softap_get_station_num

Posted: Mon Mar 21, 2016 9:57 pm
by Fugazi
wifi_softap_get_station_num is being updated much before wifi_softap_get_station_info, so if the connect takes sometime, it reports a clients connected but wifi_softap_get_station_info comes back null.

Sometimes wifi_softap_get_station_info will stay null with a client connected permanently.

Should wifi_softap_get_station_num be updated after the wifi_softap_get_station_info!=null ?


Total connected_client are = 0
Total connected_client are = 0
Total connected_client are = 1 ->wifi_softap_get_station_info should not be null from here?
Total connected_client are = 1
Total connected_client are = 1
Total connected_client are = 1
Total connected_client are = 1
Total connected_client are = 1
Total connected_client are = 1
Total connected_client are = 1
Total connected_client are = 1
Total connected_client are = 1
Total connected_client are = 1
Total connected_client are = 1
Total connected_client are = 1
Total connected_client are = 1
Total connected_client are = 1
Total connected_client are = 1
client= 1 ip address is = 192.168.4.2 with mac adress is = 106675E0DB9
Total connected_client are = 1
client= 1 ip address is = 192.168.4.2 with mac adress is = 106675E0DB9
Total connected_client are = 1
client= 1 ip address is = 192.168.4.2 with mac adress is = 106675E0DB9
Total connected_client are = 1

#include <ESP8266WiFi.h>

extern "C" {
#include <user_interface.h>
}

void client_status( )
{

unsigned char number_client;
struct station_info *stat_info;

struct ip_addr *IPaddress;
IPAddress address;
int i=1;

number_client= wifi_softap_get_station_num();
yield();
delay(100);
stat_info = wifi_softap_get_station_info();

Serial.print("Total connected_client are = ");
Serial.println(number_client);

while (stat_info != NULL)
{
IPaddress = &stat_info->ip;
address = IPaddress->addr;

Serial.print("client= ");

Serial.print(i);
Serial.print(" ip address is = ");
Serial.print((address));
Serial.print(" with mac address is = ");

Serial.print(stat_info->bssid[0],HEX);
Serial.print(stat_info->bssid[1],HEX);
Serial.print(stat_info->bssid[2],HEX);
Serial.print(stat_info->bssid[3],HEX);
Serial.print(stat_info->bssid[4],HEX);
Serial.println(stat_info->bssid[5],HEX);

stat_info = STAILQ_NEXT(stat_info, next);
i++;
}
delay(100);
}

void setup() {
Serial.begin(115200);
delay(10);
WiFi.mode(WIFI_AP);
WiFi.softAP("testAP","12345678");
WiFi.printDiag(Serial);
}

void loop ()
{
client_status();
}

Re: wifi_softap_get_station_num

Posted: Tue Mar 22, 2016 10:19 am
by ESP_Faye
Hi,

Yes, wifi_softap_get_station_num is faster than wifi_softap_get_station_info.

wifi_softap_get_station_num will turn to be 1, if a station connected to the ESP8266 softAP.
wifi_softap_get_station_info depends on DHCP. After DHCP done, the station got IP address from ESP8266 softAP, the API will return the information, not null. And so if the DHCP is disable, wifi_softap_get_station_info will always be null.

Re: wifi_softap_get_station_num

Posted: Tue Mar 22, 2016 9:01 pm
by Fugazi
Surely they should be updated in sync ?

Most people will check for number of clients connected then immediately get their IP so they can deal with the incoming connection ?

Think this needs changing asap as at the moment its telling you a client is connected when its not yet connected ....

Or even better just have a wifi_connected_on_dhcp_num... which would be much more preferable, is there any point knowing a client has connected but hasnt got its IP yet, as you cant do anything with it ?

Sometimes wifi_softap_get_station_info(); never gets updated when a client has got its IP, at the moment in my code I have to start searching the common IP addresses that the DHCP Server gives out to find a connection, horribly slow and a bad way of doing it, but I have no other options?


Thanks

Re: wifi_softap_get_station_num

Posted: Sun Jul 17, 2016 11:33 pm
by Marco
I have the same problem! Sometimes "wifi_softap_get_station_info();" never gets updated when a client connected.

Re: wifi_softap_get_station_num

Posted: Sun Feb 26, 2017 6:49 pm
by ewald
I am using the data that comes with the event directly, and that seems to work more reliably:

void wifiEventHandler(System_Event_t *event) {
switch (event->event) {
case WIFI_EVENT_SOFTAPMODE_STACONNECTED:
case WIFI_EVENT_SOFTAPMODE_STADISCONNECTED: {
char mac[32] = {0};
snprintf(mac, 32, MACSTR ", aid: %d" , MAC2STR(event->event_info.sta_connected.mac), event->event_info.sta_connected.aid);
Serial.println(mac);
}
break;
}

Per the source code, this is the way the events get generated anyhow:
WiFiEventHandler ESP8266WiFiGenericClass::onSoftAPModeStationConnected(std::function<void(const WiFiEventSoftAPModeStationConnected&)> f)
{
WiFiEventHandler handler = std::make_shared<WiFiEventHandlerOpaque>(WIFI_EVENT_SOFTAPMODE_STACONNECTED, [f](System_Event_t* e){
auto& src = e->event_info.sta_connected;
WiFiEventSoftAPModeStationConnected dst;
memcpy(dst.mac, src.mac, 6);
dst.aid = src.aid;
f(dst);
});
sCbEventList.push_back(handler);
return handler;
}

Ewald

Re: wifi_softap_get_station_num

Posted: Sat Feb 24, 2018 6:40 am
by maab2050
hi
my problem is this:
"Think this needs changing asap as at the moment its telling you a client is connected when its not yet connected ...."
how can fix it ?
please help me?

Re: wifi_softap_get_station_num

Posted: Sat Oct 06, 2018 11:23 am
by www.mshd.ir
hi.
i have the same error.
1-when i call wifi_softap_get_station_num() ; it return for example 3 but why when i visit all records in wifi_softap_get_station_info(); then
list has 1 or 2 record!!!???

2-and why when i config esp8266 as softap and connected to it by my laptop then print all record in wifi_softap_get_station_info(); and find my laptop mac and ip so AT THIS TIME i call ESP.restart(); then esp rebooted but i call wifi_softap_get_station_info(); and see for example 3 (a number that larger than 1) and then print all records in wifi_softap_get_station_info(); and see this list is EMPTY!!! at this time i was visit the EMPTY result in by BROWSER and this means my laptop was reconected quickly to ESP but why wifi_softap_get_station_info(); is EMPTY and wifi_softap_get_station_info(); return number larger than 1 !!!

my esp info:
SDK Version Core Version Boot Version
2.2.1(cfd48f3) 2_4_2 31

Re: wifi_softap_get_station_num

Posted: Fri Oct 12, 2018 8:50 pm
by Her Majesty
ESP8266 RTOS SDK changes to be ESP-IDF style recently, and far more active than non OS. Maybe use RTOS SDK is a better choice..https://github.com/espressif/ESP8266_RTOS_SDK