Page 1 of 1
Getting netif
Posted: Tue Feb 06, 2018 6:40 pm
by maximkulkin
ESP32 integrates with LWIP for network stack which has a "netif" data structure. Some LWIP functions take "struct netif *" as arguments. tcpip_adapter component manages netif structures and provides functions to manipulate them. It also has a enum - tcpip_adapter_if_t - to point to particular network interface. The problem is that there is no function to get "struct netif *" based on tcpip_adapter_if_t to pass it to LWIP functions. ESP8266 SDK had system_get_netif() function for that.
How can I get netif based on tcpip_adapter_if_t ?
Re: Getting netif
Posted: Wed Feb 07, 2018 3:21 am
by WiFive
tcpip_adapter_get_netif
Re: Getting netif
Posted: Sun Dec 15, 2019 9:47 am
by JoeSensoric
I found a netif-solution:
Code: Select all
esp_netif_t* netif=NULL;
netif = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF");
For AP-mode the parameter is "WIFI_AP_DEF"
I found this in the component sources, the ifkey parameter is not really explained.
Re: Getting netif
Posted: Thu Apr 30, 2020 12:41 pm
by vinimac
Hi,
How do I set Wifi as default interface?
Code: Select all
void setWifidefault()
{
esp_netif_t* netif = NULL;
netif = esp_netif_get_handle_from_ifkey("WIFI_AP_DEF");
netif_set_default(netif->lwip_netif);
}
error: dereferencing pointer to incomplete type 'esp_netif_t' {aka 'struct esp_netif_obj'}
Re: Getting netif
Posted: Thu Jul 28, 2022 4:03 pm
by phatpaul
JoeSensoric wrote: ↑Sun Dec 15, 2019 9:47 am
I found a netif-solution:
Code: Select all
esp_netif_t* netif=NULL;
netif = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF");
For AP-mode the parameter is "WIFI_AP_DEF"
I found this in the component sources, the ifkey parameter is not really explained.
Thanks for posting this, it's just what I was looking for! Not sure why it isn't used in any official examples.