'how to get esp32 ip address ,which is being connected to local network

I need to know the IP address of ESP32 on the local network(without printing ip on serial monitor ). The idea is to do mDNS or UDP broadcast to send the IP to the android application. The app will then use that IP to do the communication. Is there someone who has already done it?



Solution 1:[1]

Maybe a bit late, but nevertheless:

The function called "tcpip_adapter_get_ip_info" can be used to obtain your interface IP address, netmask and gateway. You can pass in TCPIP_ADAPTERE_IF_STA to get the information you desire.

    #include <tcpip_adapter.h>

    tcpip_adapter_ip_info_t ipInfo; 
    char str[256];
        
    tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ipInfo);
    sprintf(str, "%x", ipInfo.ip.addr);

Note that it is also given in the event handler:

    case SYSTEM_EVENT_STA_GOT_IP:
        eprintf(eLOG_EVENTQ,"IP: %s\r\n", 
        ip4addr_ntoa(&event>event_info.got_ip.ip_info.ip));

Solution 2:[2]

If you're looking to identify your ESP32 easily on the local network, you can simply use the mDNS service.

This will make your ESP32 accessible via user friendly hostname.

Example: myesp32.local

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 PaintedBlck
Solution 2 Bayrem Gharsellaoui