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

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

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

Postby kolban » Sun Oct 09, 2016 11:08 pm

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.
Last edited by kolban on Mon Jan 23, 2017 5:40 pm, edited 1 time in total.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

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

Postby kolban » Mon Jan 23, 2017 5:43 am

*** bump ***
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

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

Postby ESP_igrr » Mon Jan 23, 2017 6:24 am

This looks correct because when the station has just connected, it is possible that DHCP server has not yet assigned it an IP address.

Fugazi
Posts: 42
Joined: Wed Apr 26, 2017 9:05 pm

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

Postby Fugazi » Fri Apr 28, 2017 7:43 am

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

ESP_Sprite
Posts: 9759
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_Sprite » Sat Apr 29, 2017 3:23 pm

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.

Fugazi
Posts: 42
Joined: Wed Apr 26, 2017 9:05 pm

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

Postby Fugazi » Sun Apr 30, 2017 9:11 am

Thanks, sorted that now :)

Who is online

Users browsing this forum: No registered users and 161 guests