Page 1 of 1

[Answered] Calling tcpip_adapter_get_sta_list() in an event handler for SYSTEM_EVENT_AP_STACONNECTED

Posted: Sun Oct 09, 2016 11:08 pm
by kolban
My app is registering itself as an access point and when a station connects, it is asking for the station list and then using tcpip_adapter_get_sta_list() to augment the data with the IP address of the connected stations. I seem to see that at that time, the IP address of the connected station is "0". Here is my code fragment:

Code: Select all

		struct station_info *stations;
		ESP_ERROR_CHECK(esp_wifi_get_station_list(&stations));
		struct station_list *infoList;
	
		ESP_ERROR_CHECK(tcpip_adapter_get_sta_list(stations, &infoList));
		struct station_list *head = infoList;		
		while(infoList != NULL) {
			printf("mac: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x " IPSTR " %d\n",
					infoList->mac[0],infoList->mac[1],infoList->mac[2],
					infoList->mac[3],infoList->mac[4],infoList->mac[5],
					IP2STR(&(infoList->ip)),
					(uint32_t)(infoList->ip.addr));
			infoList = STAILQ_NEXT(infoList, next);
		}
		ESP_ERROR_CHECK(esp_adapter_free_sta_list(head));
		ESP_ERROR_CHECK(esp_wifi_free_station_list());
Is this expected behavior? I can see that being correct ... that when we get an event that a station has connected, it doesn't yet have an allocated IP address.

Re: Calling tcpip_adapter_get_sta_list() in an event handler for SYSTEM_EVENT_AP_STACONNECTED

Posted: Mon Jan 23, 2017 5:43 am
by kolban
*** bump ***

Re: Calling tcpip_adapter_get_sta_list() in an event handler for SYSTEM_EVENT_AP_STACONNECTED

Posted: Mon Jan 23, 2017 6:24 am
by ESP_igrr
This looks correct because when the station has just connected, it is possible that DHCP server has not yet assigned it an IP address.

Re: [Answered] Calling tcpip_adapter_get_sta_list() in an event handler for SYSTEM_EVENT_AP_STACONNECTED

Posted: Fri Apr 28, 2017 7:43 am
by Fugazi
Hi,


Sorry for the noobie question, but I am trying to do the same here.

However esp_wifi.h within the github code doesnt have

esp_wifi_get_station_list

Its only mentioned within the esp32-idf pages.

Seems two different files, is this code not added to the release in github or ?

Thanks

Re: [Answered] Calling tcpip_adapter_get_sta_list() in an event handler for SYSTEM_EVENT_AP_STACONNECTED

Posted: Sat Apr 29, 2017 3:23 pm
by ESP_Sprite
The post you replied to already is pretty old (that is, when keeping in mind esp-idf is pretty young), and I think the API has changed. If you look in the API docs, you'll find that esp_wifi_ap_get_sta_list probably does what you want.

Re: [Answered] Calling tcpip_adapter_get_sta_list() in an event handler for SYSTEM_EVENT_AP_STACONNECTED

Posted: Sun Apr 30, 2017 9:11 am
by Fugazi
Thanks, sorted that now :)