@@ -87,24 +87,29 @@ char* IRAM_ATTR wifi_info_handler(void)
8787 tcpip_adapter_ip_info_t ip_info ;
8888 tcpip_adapter_dns_info_t dns_info ;
8989 int8_t rssi = 0 ;
90- char * dns = "" ;
91- char * ip_address = "" ;
92- memset ( & ap_info , 0 , sizeof ( ap_info )) ;
90+ char gateway_address [ 32 ] ;
91+ char ip_address [ 32 ] ;
92+ char dns [ 32 ] ;
9393 if (ap_connect )
9494 {
95+ memset (& ap_info , 0 , sizeof (ap_info ));
96+ memset (& ip_info , 0 , sizeof (ip_info ));
9597 if (esp_wifi_sta_get_ap_info (& ap_info ) == ESP_OK )
9698 {
9799 rssi = ap_info .rssi ;
98- tcpip_adapter_get_ip_info (TCPIP_ADAPTER_IF_STA , & ip_info );
99- ip_address = ip4addr_ntoa (& ip_info .ip );
100- tcpip_adapter_get_dns_info (TCPIP_ADAPTER_IF_STA , ESP_NETIF_DNS_MAIN , & dns_info );
101- dns = ip4addr_ntoa ((ip4_addr_t * )& dns_info .ip );
100+ ESP_ERROR_CHECK (tcpip_adapter_get_ip_info (TCPIP_ADAPTER_IF_STA , & ip_info ));
101+ ESP_ERROR_CHECK (tcpip_adapter_get_dns_info (TCPIP_ADAPTER_IF_STA , ESP_NETIF_DNS_MAIN , & dns_info ));
102+
103+ strlcpy (gateway_address , ip4addr_ntoa (& ip_info .gw ), sizeof (gateway_address ));
104+ strlcpy (ip_address , ip4addr_ntoa (& ip_info .ip ), sizeof (ip_address ));
105+ strlcpy (dns , ip4addr_ntoa ((ip4_addr_t * )& dns_info .ip ), sizeof (dns ));
102106 }
103107 else
104108 {
105109 rssi = 0 ;
106- dns = "" ;
107- ip_address = "" ;
110+ strcpy (gateway_address , "" );
111+ strcpy (ip_address , "" );
112+ strcpy (dns , "" );
108113 }
109114 }
110115 memset (& wifi_sta_list , 0 , sizeof (wifi_sta_list ));
@@ -113,8 +118,9 @@ char* IRAM_ATTR wifi_info_handler(void)
113118 ESP_ERROR_CHECK (tcpip_adapter_get_sta_list (& wifi_sta_list , & adapter_sta_list ));
114119
115120 cJSON * root = cJSON_CreateObject ();
121+ cJSON_AddStringToObject (root , "gatewayAddress" , gateway_address );
116122 cJSON_AddStringToObject (root , "ipAddress" , ip_address );
117- cJSON_AddStringToObject (root , "gatewayAddress" , dns );
123+ cJSON_AddStringToObject (root , "dns" , ( has_static_ip || IsCustomDnsEnable ) ? customDNSip : dns );
118124 cJSON_AddNumberToObject (root , "rss" , rssi );
119125 cJSON_AddBoolToObject (root , "wifiAuthFail" , IsWifiAuthFail );
120126 cJSON * clients = cJSON_AddArrayToObject (root , "clients" );
0 commit comments