diff --git a/components/esp32/event.c b/components/esp32/event.c index d8e5c0a4fb..fa1830e47e 100644 --- a/components/esp32/event.c +++ b/components/esp32/event.c @@ -13,6 +13,7 @@ // limitations under the License. #include #include +#include #include "esp_err.h" #include "esp_wifi.h" @@ -77,6 +78,12 @@ static esp_err_t system_event_sta_gotip_default(system_event_t *event) { extern esp_err_t esp_wifi_set_sta_ip(void); WIFI_API_CALL_CHECK("esp_wifi_set_sta_ip", esp_wifi_set_sta_ip(), ESP_OK); + + printf("ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR "\n", + IP2STR(&event->event_info.got_ip.ip), + IP2STR(&event->event_info.got_ip.netmask), + IP2STR(&event->event_info.got_ip.gw)); + return ESP_OK; } @@ -134,6 +141,19 @@ esp_err_t system_event_sta_connected_handle_default(system_event_t *event) if (status == TCPIP_ADAPTER_DHCP_INIT) { tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA); + } else if (status == TCPIP_ADAPTER_DHCP_STOPPED) { + struct ip_info ip_info; + system_event_t evt; + + tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info); + + //notify event + evt.event_id = SYSTEM_EVENT_STA_GOTIP; + memcpy(&evt.event_info.got_ip.ip, &ip_info.ip, sizeof(evt.event_info.got_ip.ip)); + memcpy(&evt.event_info.got_ip.netmask, &ip_info.netmask, sizeof(evt.event_info.got_ip.netmask)); + memcpy(&evt.event_info.got_ip.gw, &ip_info.gw, sizeof(evt.event_info.got_ip.gw)); + + esp_event_send(&evt); } return ESP_OK; diff --git a/components/tcpip_adapter/include/tcpip_adapter.h b/components/tcpip_adapter/include/tcpip_adapter.h index 8726ac8330..8a51eae0f4 100644 --- a/components/tcpip_adapter/include/tcpip_adapter.h +++ b/components/tcpip_adapter/include/tcpip_adapter.h @@ -17,6 +17,8 @@ #include +#include "rom/queue.h" + #include "esp_wifi.h" #define CONFIG_TCPIP_LWIP 1 @@ -24,7 +26,13 @@ #if CONFIG_TCPIP_LWIP #include "lwip/ip_addr.h" -#include "rom/queue.h" + +#define IP2STR(ipaddr) ip4_addr1_16(ipaddr), \ + ip4_addr2_16(ipaddr), \ + ip4_addr3_16(ipaddr), \ + ip4_addr4_16(ipaddr) + +#define IPSTR "%d.%d.%d.%d" struct ip_info { ip4_addr_t ip; diff --git a/components/tcpip_adapter/tcpip_adapter_lwip.c b/components/tcpip_adapter/tcpip_adapter_lwip.c index bf1d6a73ca..3fb42aeb13 100644 --- a/components/tcpip_adapter/tcpip_adapter_lwip.c +++ b/components/tcpip_adapter/tcpip_adapter_lwip.c @@ -74,9 +74,8 @@ esp_err_t tcpip_adapter_start(tcpip_adapter_if_t tcpip_if, uint8_t *mac, struct if (dhcps_status == TCPIP_ADAPTER_DHCP_INIT) { dhcps_start(esp_netif[tcpip_if], info); - printf("dhcp server start:(ip: %s, ", inet_ntoa(info->ip)); - printf("mask: %s, ", inet_ntoa(info->netmask)); - printf("gw: %s)\n", inet_ntoa(info->gw)); + printf("dhcp server start:(ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR ")\n", + IP2STR(&info->ip), IP2STR(&info->netmask), IP2STR(&info->gw)); dhcps_status = TCPIP_ADAPTER_DHCP_STARTED; } @@ -456,10 +455,6 @@ static void tcpip_adapter_dhcpc_cb(void) memcpy(&evt.event_info.got_ip.gw, &ip_info->gw, sizeof(evt.event_info.got_ip.gw)); esp_event_send(&evt); - - printf("ip: %s, ", inet_ntoa(ip_info->ip)); - printf("mask: %s, ", inet_ntoa(ip_info->netmask)); - printf("gw: %s\n", inet_ntoa(ip_info->gw)); } else { TCPIP_ADAPTER_DEBUG("ip unchanged\n"); }