Page 1 of 1

[Solved] Being a WiFi station but not using DHCP ...

Posted: Sun Oct 16, 2016 2:00 am
by kolban
Studying the WiFi exposed APIs in ESP-IDF, it seems that the correct path to be a station is to:
  • tcpip_adapter_init()
  • esp_wifi_init()
  • esp_wifi_set_mode()
  • esp_wifi_set_config()
  • esp_wifi_start()
  • esp_wifi_connect()
That seems to assume that my station (ESP32) is going to use the services of a DHCP provider to obtain local IP address, gateway and netmask. Looking the the tcpip_adapter APIs, I see we have an API called tcpip_adapter_start() that allows me to specify my own IP address, gateway and netmask. Perfect. However, what I don't understand if where to inject this API call in the above sequence of WiFi calls in order for the function to be honored. Note that this assumes that I am even down the right track which is still subject to discussion :-)

Re: Being a WiFi station but not using DHCP ...

Posted: Sun Oct 16, 2016 3:05 am
by WiFive
tcpip_adapter_init()
tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA)
tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &static_IP_info)

Re: Being a WiFi station but not using DHCP ...

Posted: Sun Oct 16, 2016 5:14 am
by kolban
Many thanks, so the full recipe would be:
  • tcpip_adapter_init()
  • tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA)
  • tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &static_IP_info)
  • esp_wifi_init()
  • esp_wifi_set_mode()
  • esp_wifi_set_config()
  • esp_wifi_start()
  • esp_wifi_connect()
I tested and it seems to work perfectly. The code fragment I used to set the static IP info is as follows in case it is useful to someone:

Code: Select all

tcpip_adapter_ip_info_t ipInfo;
IP4_ADDR(&ipInfo.ip, 192,168,1,99);
IP4_ADDR(&ipInfo.gw, 192,168,1,1);
IP4_ADDR(&ipInfo.netmask, 255,255,255,0);
tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &ipInfo);
That sounds great. Thank you VERY MUCH. You have awesome knowledge.

Re: [Solved] Being a WiFi station but not using DHCP ...

Posted: Fri Apr 05, 2019 9:36 am
by johto391
Hi Kolban,
On which esp-idf version did you get the tcpip_adapter_dhcpc_stop to work for interface TCPIP_ADAPTER_IF_STA?
// Johan

Re: [Solved] Being a WiFi station but not using DHCP ...

Posted: Fri Feb 14, 2020 9:29 pm
by Fredrik
tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA) returns ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS for me.

I guess it works on some versions.
So is there a way to set a static ip?