Getting netif

maximkulkin
Posts: 5
Joined: Tue Feb 06, 2018 6:25 pm

Getting netif

Postby maximkulkin » Tue Feb 06, 2018 6:40 pm

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 ?

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Getting netif

Postby WiFive » Wed Feb 07, 2018 3:21 am

tcpip_adapter_get_netif

JoeSensoric
Posts: 29
Joined: Fri Mar 03, 2017 10:31 am

Re: Getting netif

Postby JoeSensoric » 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.

vinimac
Posts: 24
Joined: Sun May 06, 2018 1:04 pm

Re: Getting netif

Postby vinimac » Thu Apr 30, 2020 12:41 pm

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'}

phatpaul
Posts: 110
Joined: Fri Aug 24, 2018 1:14 pm

Re: Getting netif

Postby phatpaul » Thu Jul 28, 2022 4:03 pm

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.

Who is online

Users browsing this forum: Bing [Bot], mejhaMA and 98 guests