Hi All,
Does anyone know an easy way to figure out the IP addresses of all connected stations on the esp32? When a station connects or disconnects I only get the mac address. I know I can then get the IP from the mac address with a another call but is there another API call to get a list of connected station IP's?
Thanks
Imtiaz
connected wifi stations
Re: connected wifi stations
Well hmmm .... that was harder than it should have been. From my study, I believed that the answer was the tcpip_adapter component but after a search I could'nt find any docs in the web site on that component. Has it been accidently missed from the inclusion in the web based docs?
The answer to your question though can be technically found here ...
https://github.com/espressif/esp-idf/bl ... ter.h#L423
The API you are likely going to want to use is called:
tcpip_adapter_get_sta_list()
The answer to your question though can be technically found here ...
https://github.com/espressif/esp-idf/bl ... ter.h#L423
The API you are likely going to want to use is called:
tcpip_adapter_get_sta_list()
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: connected wifi stations
Hi Kolban,
Thanks a bunch. I'll give it a go now .
Imtiaz
Thanks a bunch. I'll give it a go now .
Imtiaz
Re: connected wifi stations
Hi Kolban ,
I tried it it doesnt work .
Station IP comes out at 0 even if I have two stations connected.
I (149840) wifi: n:1 0, o:1 0, ap:1 1, sta:255 255, prof:1
I (149840) wifi: station: 90:68:c3:5b:f7:66 join, AID=2, n, 20
D (149841) event: SYSTEM_EVENT_AP_STACONNECTED, mac:90:68:c3:5b:f7:66, aid:2
OTA esp32.core Image Running
Mac : 194 , STA IP : 0
Num: 1 , Mac : 194
Mac : 0 , STA IP : 0
Num: 1 , Mac : 251
Mac : 0 , STA IP : 0
Num: 1 , Mac : 132
Mac : 0 , STA IP : 0
Num: 1 , Mac : 251
OTA esp32.core Image Running
Mac : 194 , STA IP : 0
Num: 1 , Mac : 194
Mac : 0 , STA IP : 0
Num: 1 , Mac : 251
Mac : 0 , STA IP : 0
Num: 1 , Mac : 132
Mac : 0 , STA IP : 0
Num: 1 , Mac : 251
I tried it it doesnt work .
Code: Select all
void printStationLists(void)
{
wifi_sta_list_t wifi_sta_list;
tcpip_adapter_sta_list_t tcp_sta_list;
if(tcpip_adapter_get_sta_list(&wifi_sta_list, &tcp_sta_list) == ESP_OK)
{
for(uint8_t i = 0; i<4 ; i++)
{
TRACE_D("Mac : %d , STA IP : %d\n",tcp_sta_list.sta[i].mac[0] ,tcp_sta_list.sta[i].ip.addr);
TRACE_D("Num: %d , Mac : %d\n",wifi_sta_list.num,wifi_sta_list.sta[i].mac[0]);
}
}
else
{
TRACE_E("Cant get sta list\n");
}
}
I (149840) wifi: n:1 0, o:1 0, ap:1 1, sta:255 255, prof:1
I (149840) wifi: station: 90:68:c3:5b:f7:66 join, AID=2, n, 20
D (149841) event: SYSTEM_EVENT_AP_STACONNECTED, mac:90:68:c3:5b:f7:66, aid:2
OTA esp32.core Image Running
Mac : 194 , STA IP : 0
Num: 1 , Mac : 194
Mac : 0 , STA IP : 0
Num: 1 , Mac : 251
Mac : 0 , STA IP : 0
Num: 1 , Mac : 132
Mac : 0 , STA IP : 0
Num: 1 , Mac : 251
OTA esp32.core Image Running
Mac : 194 , STA IP : 0
Num: 1 , Mac : 194
Mac : 0 , STA IP : 0
Num: 1 , Mac : 251
Mac : 0 , STA IP : 0
Num: 1 , Mac : 132
Mac : 0 , STA IP : 0
Num: 1 , Mac : 251
Re: connected wifi stations
This works
Code: Select all
/************************************************************
@Inputs:
@Outputs:
@Comments:
*************************************************************/
void printStationLists(void)
{
{
ip4_addr_t addr;
wifi_sta_list_t staList;
esp_wifi_ap_get_sta_list(&staList);
for(uint8_t i = 0 ; i<staList.num ; i++)
{
if(dhcp_search_ip_on_mac(staList.sta[i].mac , &addr))
{
TRACE_D("IP = %d\n",addr.addr);
}
else
{
}
}
}
}
Re: connected wifi stations
HI,
I have got the following code work. You can try this.
I have got the following code work. You can try this.
Code: Select all
esp_wifi_ap_get_sta_list(&wifi_sta_list);
tcpip_adapter_get_sta_list(&wifi_sta_list, &tcpip_adapter_sta_list);
for (i=0; i<wifi_sta_list.num; i++){
printf("StaInfo:"MACSTR","IPSTR"",MAC2STR(wifi_sta_list.sta[i].mac),IP2STR(&tcpip_adapter_sta_list.sta[i].ip));
}
Who is online
Users browsing this forum: Baidu [Spider], noweare and 190 guests