You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
I have searched the issue tracker for a similar issue and not found a similar issue.
General issue report
I have an esp32-s3 device and I am trying to read its assigned local Wi-Fi IP address as below using esp_netif_get_default_netif()
This does not work unfortunately. intf is not NULL, but doesn't get the actual IP address etc.
What is strange however is that this actually worked on a previous network, but not on the current one.
I need to obtain the IP address automatically because I need to delegate an mDNS hostname using mdns_delegate_hostname_add() .
Hard-coding the device IP address works fine and the mDNS server works as expected then, but of course the address needs to be read from the network interface somehow.
esp_netif_t *intf = esp_netif_get_default_netif();;
while (intf == NULL)
{
ESP_LOGE(TAG, "ERROR ! netif is NULL");
sleep(2);
intf = esp_netif_get_default_netif();
}
mdns_ip_addr_t addr4, addr6;
addr4.addr.type = ESP_IPADDR_TYPE_V4;
esp_netif_ip_info_t info;
esp_netif_get_ip_info(intf, &info);
// IP address is 0.0.0.0 when printed
ESP_LOGI(TAG, "IP Address of device is : " IPSTR "\n", IP2STR(&info.ip));
The text was updated successfully, but these errors were encountered:
github-actionsbot
changed the title
How to properly read the local IP address of the device
How to properly read the local IP address of the device (IDFGH-14355)
Jan 5, 2025
The issue arises because the DHCP client hasn't yet assigned an IP address to the interface when you're calling esp_netif_get_ip_info(), so it returns 0.0.0.0. This is expected behavior during the network setup phase. Instead of polling for the network interface, use the ESP-IDF event system to listen for the IP_EVENT_STA_GOT_IP event, which indicates that the interface has acquired a valid IP address. This ensures you only attempt to retrieve the IP once it’s ready, avoiding timing issues. After receiving the event, you can safely use the IP address for tasks like delegating the mDNS hostname.
@nopnop2002@david-cermak Thanks. I have solved it now. Assigning a callback to assign the hostname when IP_EVENT_STA_GOT_IP occurs works the best for me.
Answers checklist.
General issue report
I have an esp32-s3 device and I am trying to read its assigned local Wi-Fi IP address as below using
esp_netif_get_default_netif()
This does not work unfortunately.
intf
is not NULL, but doesn't get the actual IP address etc.What is strange however is that this actually worked on a previous network, but not on the current one.
I need to obtain the IP address automatically because I need to delegate an mDNS hostname using
mdns_delegate_hostname_add()
.Hard-coding the device IP address works fine and the mDNS server works as expected then, but of course the address needs to be read from the network interface somehow.
The text was updated successfully, but these errors were encountered: