Using both ethernet and wifi interfaces

dsa_doge
Posts: 1
Joined: Tue Nov 23, 2021 10:33 am

Using both ethernet and wifi interfaces

Postby dsa_doge » Tue Nov 23, 2021 10:59 am

Hi

We use esp-idf 3.3.5 in commercial project, so I will ask if my problem could be solved in this version of esp-idf, but I know we might have to switch to esp-idf 4 anyway...

I need to use both internet interfaces in my work:
-ethernet for peer to peer connection with some device - we already did this and it works: both devices are connected with ethernet cable and have static IP addresses and communicate using AMQP protocol
-wifi connection to access cloud database using AMQP protocol - it already works

The problem is when I try to integrate both branches and both functionalities, AMQP connects to given host using sockets interface and I have no idea how to switch between interfaces, doing nothing ends in expected: local IP address of my device is not accessible on wifi interface and vice versa database is not accessible on ethernet LAN connection.

I found `netif_set_default` function which switches between interfaces and set default interface to wifi if both wifi and ethernet are up. Is there any simple way to use both interfaces in esp-idf 3.5.1?

ESP_cermak
Posts: 69
Joined: Thu Nov 01, 2018 8:32 am

Re: Using both ethernet and wifi interfaces

Postby ESP_cermak » Wed Nov 24, 2021 5:18 pm

Hi dsa_doge

It's easier to switch to IDF v4.x, but this should work correctly on v3.3, too.
You can check this example: https://github.com/espressif/esp-idf/tr ... _multi_net to see how to work with different network interfaces on socket layer.

Are both interfaces on the same subnet? If yes, you can enable `IP_FORWARD` to benefit from simple packet forwarding implemented in lwip, but if I understand your use case correctly, you don't really need that. You just have to control the interface which you're connecting to and the socket API should be enough (i.e. binding the client's socket to the specific interface/or address)

Who is online

Users browsing this forum: ok-home, Urada_esp and 89 guests