简体   繁体   中英

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?

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));

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM