Why esp_netif_get_ip_info() does not seem to be working
Posted: Mon Dec 07, 2020 10:09 am
Hello,
I'm trying to get the IP settings of a softAP access point.
Using the examples\wifi\getting_started\softAP\main\softap_example_main.c I added a wifi_event_handler() and waited for WIFI_EVENT_AP_STACONNECTED before calling esp_netif_get_ip_info(). Unfortunately I get the following result:
I (13483) wifi softAP: AP IP:192.168.4.1, mask:192.168.4.1, gw:192.168.4.1
using the following code:
if (bits & WIFI_CONNECTED_BIT) {
ESP_LOGI(TAG, "Connected");
esp_netif_ip_info_t ip_info;
esp_netif_get_ip_info(esp_netif_ap, &ip_info);
ESP_LOGI(TAG, "AP IP:%s, mask:%s, gw:%s", ip4addr_ntoa((ip4_addr_t*)&ip_info.ip),
ip4addr_ntoa((ip4_addr_t*)&ip_info.netmask),
ip4addr_ntoa((ip4_addr_t*)&ip_info.gw));
}
I then added an ip_event_handler() and retried waiting until I got the IP_EVENT_AP_STAIPASSIGNED event but get the same result:
I (13523) wifi softAP: AP Assigned IP:192.168.4.1, mask:192.168.4.1, gw:192.168.4.1
using the following code:
if (bits & IP_AP_STAIPASSIGNED) {
esp_netif_ip_info_t ip_info;
esp_netif_get_ip_info(esp_netif_ap, &ip_info);
ESP_LOGI(TAG, "AP Assigned IP:%s, mask:%s, gw:%s", ip4addr_ntoa((ip4_addr_t*)&ip_info.ip),
ip4addr_ntoa((ip4_addr_t*)&ip_info.netmask),
ip4addr_ntoa((ip4_addr_t*)&ip_info.gw));
}
Can someone please let me know why the netmask is 192.168.4.1 and not a netmask representation like 255.255.255.0 at least?
I understand that the gateway is 192.168.4.1 as that is the AP address.
The reason I require the info is that we supply the network information when the device is a station but if the device is set-up as an AP (softAP) then I don't get the information to supply to the user.
Best regards,
Charles
I'm trying to get the IP settings of a softAP access point.
Using the examples\wifi\getting_started\softAP\main\softap_example_main.c I added a wifi_event_handler() and waited for WIFI_EVENT_AP_STACONNECTED before calling esp_netif_get_ip_info(). Unfortunately I get the following result:
I (13483) wifi softAP: AP IP:192.168.4.1, mask:192.168.4.1, gw:192.168.4.1
using the following code:
if (bits & WIFI_CONNECTED_BIT) {
ESP_LOGI(TAG, "Connected");
esp_netif_ip_info_t ip_info;
esp_netif_get_ip_info(esp_netif_ap, &ip_info);
ESP_LOGI(TAG, "AP IP:%s, mask:%s, gw:%s", ip4addr_ntoa((ip4_addr_t*)&ip_info.ip),
ip4addr_ntoa((ip4_addr_t*)&ip_info.netmask),
ip4addr_ntoa((ip4_addr_t*)&ip_info.gw));
}
I then added an ip_event_handler() and retried waiting until I got the IP_EVENT_AP_STAIPASSIGNED event but get the same result:
I (13523) wifi softAP: AP Assigned IP:192.168.4.1, mask:192.168.4.1, gw:192.168.4.1
using the following code:
if (bits & IP_AP_STAIPASSIGNED) {
esp_netif_ip_info_t ip_info;
esp_netif_get_ip_info(esp_netif_ap, &ip_info);
ESP_LOGI(TAG, "AP Assigned IP:%s, mask:%s, gw:%s", ip4addr_ntoa((ip4_addr_t*)&ip_info.ip),
ip4addr_ntoa((ip4_addr_t*)&ip_info.netmask),
ip4addr_ntoa((ip4_addr_t*)&ip_info.gw));
}
Can someone please let me know why the netmask is 192.168.4.1 and not a netmask representation like 255.255.255.0 at least?
I understand that the gateway is 192.168.4.1 as that is the AP address.
The reason I require the info is that we supply the network information when the device is a station but if the device is set-up as an AP (softAP) then I don't get the information to supply to the user.
Best regards,
Charles