connected wifi stations

imtiaz
Posts: 106
Joined: Wed Oct 26, 2016 1:34 am

connected wifi stations

Postby imtiaz » Thu Mar 23, 2017 7:08 pm

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

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

Re: connected wifi stations

Postby kolban » Thu Mar 23, 2017 7:16 pm

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()
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

imtiaz
Posts: 106
Joined: Wed Oct 26, 2016 1:34 am

Re: connected wifi stations

Postby imtiaz » Thu Mar 23, 2017 7:23 pm

Hi Kolban,

Thanks a bunch. I'll give it a go now .

Imtiaz

imtiaz
Posts: 106
Joined: Wed Oct 26, 2016 1:34 am

Re: connected wifi stations

Postby imtiaz » Thu Mar 23, 2017 7:56 pm

Hi Kolban ,

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

    imtiaz
    Posts: 106
    Joined: Wed Oct 26, 2016 1:34 am

    Re: connected wifi stations

    Postby imtiaz » Thu Mar 23, 2017 8:34 pm

    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
    			{
    
    			}
        	}
    	}
    
    }

    heyinling
    Posts: 19
    Joined: Thu Mar 23, 2017 7:21 am

    Re: connected wifi stations

    Postby heyinling » Tue Mar 28, 2017 1:08 pm

    HI,

    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: Bing [Bot], calebe_sucupira, ESP_Roland and 76 guests