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

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

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

Postby kolban » Sun Oct 16, 2016 2:00 am

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 :-)
Last edited by kolban on Sun Oct 16, 2016 5:40 am, edited 1 time in total.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Available for ESP32 consulting.

WiFive
Posts: 1757
Joined: Tue Dec 01, 2015 7:35 am

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

Postby WiFive » Sun Oct 16, 2016 3:05 am

tcpip_adapter_init()
tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA)
tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &static_IP_info)

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

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

Postby kolban » Sun Oct 16, 2016 5:14 am

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

Who is online

Users browsing this forum: No registered users and 2 guests