W5500 ethernet priority over Wifi

glrtheil
Posts: 61
Joined: Tue Dec 07, 2021 2:48 pm

W5500 ethernet priority over Wifi

Postby glrtheil » Thu Jun 01, 2023 4:54 pm

ESP-IDF v4.3.2

We're adding a w5500 chip to one of our long established pieces of hardware. I've got everything working correctly, but despite the interface priority of the w5500 being the default of 50, and the wifi interface priority being the default of 100, it ALWAYS attempts to use the wifi before the ethernet. The only way I can get traffic to flow over ethernet is by running esp_wifi_stop(), which seems ridiculous as it adds a ton of complexity to all the connectivity code and having to enable/disable wifi if the link state of ethernet changes.

I feel like I'm missing something. Why is the wifi interface a priority over ethernet?

Here's the code to init the w5500 config

Code: Select all

esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH();
eth_netif = esp_netif_new(&cfg);
ESP_ERROR_CHECK(esp_eth_set_default_handlers(eth_netif));
Here's the code to init wifi config

Code: Select all

wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
Happy to provide other code it necessary. Thanks!

glrtheil
Posts: 61
Joined: Tue Dec 07, 2021 2:48 pm

Re: W5500 ethernet priority over Wifi

Postby glrtheil » Wed Jun 07, 2023 2:53 pm

I've contacted Espressif support and made some progress on this. Higher prio number equals higher priority, where I assumed a lower number equaled a higher priority. This strange since typically when talking about priority, a lower number equals a higher priority. e.g. 1 is the greatest priority with 5 being the lowest.

That said, in this version of the IDF there is no way to just set the prio value, and it took me a bit to dig through code to figure out how to create a default structure. Here's the solution:

In my Ethernet.h file:

Code: Select all

#define NETIF_INHERENT_DEFAULT_ETH() \
{   \
    .flags = (esp_netif_flags_t)(ESP_NETIF_DHCP_CLIENT | ESP_NETIF_FLAG_GARP | ESP_NETIF_FLAG_EVENT_IP_MODIFIED), \
    ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(mac) \
    ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(ip_info) \
    .get_ip_event = IP_EVENT_ETH_GOT_IP, \
    .lost_ip_event = 0, \
    .if_key = "ETH_DEF", \
    .if_desc = "eth", \
    .route_prio = 150 \
};

const esp_netif_inherent_config_t _g_netif_inherent_eth_config = NETIF_INHERENT_DEFAULT_ETH();

#define NETIF_BASE_DEFAULT_ETH &_g_netif_inherent_eth_config

#define NETIF_DEFAULT_ETH()                  \
{                                            \
    .base = NETIF_BASE_DEFAULT_ETH,      \
    .driver = NULL,                          \
    .stack = ESP_NETIF_NETSTACK_DEFAULT_ETH, \
}
Implementation in init/connect function:

Code: Select all

esp_netif_config_t cfg = NETIF_DEFAULT_ETH();
esp_netif_t *eth_netif = esp_netif_new(&cfg);

SarjuBhatnagar
Posts: 1
Joined: Tue Jul 18, 2023 2:18 pm

Re: W5500 ethernet priority over Wifi

Postby SarjuBhatnagar » Wed Jul 19, 2023 5:49 pm

Is it resolved, your default configuration worked or not?
Thanks,
sarju

Who is online

Users browsing this forum: Google [Bot] and 92 guests