Hi all -
I'm trying to get a ESP32 with a fixed IP address to connect to an access point. I'm getting an error "Host is unreachable."
My calls to esp_wifi_start and esp_wifi_connect seem to be returning successfully. Is there anything special I need to do? I didn't see anything in the wifi_init_config_t struct that I need to change, but maybe I'm missing something.
Thanks for any help...
(solved) connecting to Wifi using static IP
(solved) connecting to Wifi using static IP
Last edited by mzimmers on Wed Sep 09, 2020 1:46 pm, edited 2 times in total.
-
- Posts: 47
- Joined: Sun Jan 13, 2019 5:39 pm
Re: conntecting to Wifi using static IP
Hey,
without seeing any code:
As far as I know and understand the WiFi driver is independent from the TCP/IP layer, meaning connecting to an access point has nothing to do with TCP/IP at first. After your connection is established, then your access point is assigning your device (ESP32) an IP address if DHCP is enabled on the access point. Did you check your access point settings ? Are the "static" TCP/IP configurations such IP, Gateway etc.. are configured proper on your ESP32 and are they compliant with the access point ?
Good luck !
opcode_x64
without seeing any code:
As far as I know and understand the WiFi driver is independent from the TCP/IP layer, meaning connecting to an access point has nothing to do with TCP/IP at first. After your connection is established, then your access point is assigning your device (ESP32) an IP address if DHCP is enabled on the access point. Did you check your access point settings ? Are the "static" TCP/IP configurations such IP, Gateway etc.. are configured proper on your ESP32 and are they compliant with the access point ?
Good luck !
opcode_x64
Re: connecting to Wifi using static IP
I have a recollection of a wifi lig that can be activated. I tried to find that - no luck.
That log, if it exists, might give more clues.
Tom
That log, if it exists, might give more clues.
Tom
IT Professional, Maker
Santiago, Dominican Republic
Santiago, Dominican Republic
Re: connecting to Wifi using static IP
I have a recollection of a wifi lig that can be activated. I tried to find that - no luck.
That log, if it exists, might give more clues.
Here it is:
https://docs.espressif.com/projects/esp ... m/log.html
Tom
That log, if it exists, might give more clues.
Here it is:
https://docs.espressif.com/projects/esp ... m/log.html
Tom
IT Professional, Maker
Santiago, Dominican Republic
Santiago, Dominican Republic
Re: connecting to Wifi using static IP
Thanks for the replies, guys. I already get wifi log messages, and there's nothing helpful in there.
I'll look at my AP more closely to see whether it restricts static IP addresses, though that seems unlikely.
I'll look at my AP more closely to see whether it restricts static IP addresses, though that seems unlikely.
Re: connecting to Wifi using static IP
So, here's what was missing:
In short, the calls to tcpip_adapter_dhcpc_stop() and tcpip_adapter_set_ip_info() were what was missing. Note: this is a solution for esp-idf v4.0.1. V4.1 deprecates tcpip_adapter in favor of netif.
Code: Select all
tcpip_adapter_ip_info_t m_ipInfo = { {0}, {0}, {0} };
if (m_tasks->flash->get(NVS_KEY_IPSOURCE) == IP_SOURCE_TXT[IP_SOURCE_STATIC])
{
ESP_ERROR_CHECK(tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA));
// extract elements, convert to string and pass to NVS.
s.assign(m_tasks->flash->get(NVS_KEY_IPADDR));
inet_pton(AF_INET, s.c_str(), &(m_ipInfo.ip.addr));
s.assign(m_tasks->flash->get(NVS_KEY_IPGATEWAY));
inet_pton(AF_INET, s.c_str(), &(m_ipInfo.gw.addr));
s.assign(m_tasks->flash->get(NVS_KEY_IPSUBNET));
inet_pton(AF_INET, s.c_str(), &(m_ipInfo.netmask.addr));
ESP_ERROR_CHECK(tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &m_ipInfo));
}
Who is online
Users browsing this forum: Bing [Bot] and 120 guests