Page 1 of 1

How can I get local IP?

Posted: Tue Nov 07, 2017 2:10 am
by Cannon Wang
Hi,
I'm using ESP32 as station mode, once connect to an AP I need to send my local IP to a remote server.
One way to do this is storing the IP in a global variable manually when SYSTEM_EVENT_STA_GOT_IP happend. While, how to get local IP in a recommended way?

Re: How can I get local IP?

Posted: Fri Feb 02, 2018 7:33 pm
by bbemister
I am not certain if this is the "recommended" way, but I usually do this.

Code: Select all

tcpip_adapter_ip_info_t if_info;
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &if_info);
ip4addr_ntoa_r(&(if_info.ip), ipv4_str, buflen);
You will need to include
#include <tcpip_adapter.h>
.