简体   繁体   English

如何获取esp32 ip地址,正在连接到local.network

[英]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 ).我需要知道 local.network 上 ESP32 的 IP 地址(无需在串口监视器上打印 ip)。 The idea is to do mDNS or UDP broadcast to send the IP to the android application .这个想法是做 mDNS 或 UDP 广播发送 IP 到android 应用程序 The app will then use that IP to do the communication.然后,该应用程序将使用该 IP 进行通信。 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.名为“tcpip_adapter_get_ip_info”的 function 可用于获取您的接口 IP 地址、.netmask 和网关。 You can pass in TCPIP_ADAPTERE_IF_STA to get the information you desire.您可以传入 TCPIP_ADAPTERE_IF_STA 来获取您想要的信息。

    #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 .如果您想在 local.network 上轻松识别您的 ESP32,您可以简单地使用mDNS 服务

This will make your ESP32 accessible via user friendly hostname.这将使您的 ESP32 可以通过用户友好的主机名访问。

Example: myesp32.local示例: myesp32.local

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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