wifi_softap_get_station_num

Fugazi
Posts: 9
Joined: Wed Feb 24, 2016 5:33 am

wifi_softap_get_station_num

Postby Fugazi » Mon Mar 21, 2016 9:57 pm

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();
}

ESP_Faye
Posts: 1640
Joined: Mon Oct 27, 2014 11:08 am

Re: wifi_softap_get_station_num

Postby ESP_Faye » Tue Mar 22, 2016 10:19 am

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.

Fugazi
Posts: 9
Joined: Wed Feb 24, 2016 5:33 am

Re: wifi_softap_get_station_num

Postby Fugazi » Tue Mar 22, 2016 9:01 pm

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

Marco
Posts: 6
Joined: Fri May 20, 2016 12:21 pm

Re: wifi_softap_get_station_num

Postby Marco » Sun Jul 17, 2016 11:33 pm

I have the same problem! Sometimes "wifi_softap_get_station_info();" never gets updated when a client connected.

ewald
Posts: 1
Joined: Sun Feb 26, 2017 6:42 pm

Re: wifi_softap_get_station_num

Postby ewald » Sun Feb 26, 2017 6:49 pm

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

maab2050
Posts: 3
Joined: Sat Feb 24, 2018 4:01 am

Re: wifi_softap_get_station_num

Postby maab2050 » Sat Feb 24, 2018 6:40 am

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?

User avatar
www.mshd.ir
Posts: 1
Joined: Fri Oct 05, 2018 11:16 pm

Re: wifi_softap_get_station_num

Postby www.mshd.ir » Sat Oct 06, 2018 11:23 am

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

Her Majesty
Posts: 337
Joined: Mon Oct 27, 2014 11:09 am

Re: wifi_softap_get_station_num

Postby Her Majesty » Fri Oct 12, 2018 8:50 pm

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

Who is online

Users browsing this forum: No registered users and 2 guests