Page 1 of 1

Selecting MQTT interface [IDF-1576]

Posted: Mon Apr 13, 2020 6:44 pm
by aderregibus
Hello,
I'm trying to use the MQTT library from ESP-IDF, but I need to be able to dynamically choose between WiFi, Ethernet and PPPoS.
I can't find anywhere in the documentation how to choose which interface is used by the library.
Actually, as a more general question, I couldn't find anywhere in the documentation how to choose the interface for any TCP socket connection using LWIP
Does anyone know how to do this?
Thank you!

Re: Selecting MQTT interface [IDF-1576]

Posted: Tue Apr 14, 2020 3:05 am
by ESP_Alvin
Moderator's note: edit the topic title for issue tracking, thanks.

Thanks for the suggestion, we will evaluate, thanks.

Re: Selecting MQTT interface [IDF-1576]

Posted: Wed Apr 15, 2020 7:57 am
by ESP_cermak
Hi aderregibus

lwIP uses the *default interface* for a socket to connect to, it is chosen based on user's API `netif_set_default()` provided the netif status is *up*.
ESP abstraction to the interface routing (and to the TCP/IP stack in general) is a component called esp-netif, documented here: https://docs.espressif.com/projects/esp ... netif.html
It uses an attribute `route_prio` to adjust routing priorities of multiple interfaces (if more netif's are up, the one with highest prio is chosen to be the default netif)
Updating routing priorities can be done for example like this: https://github.com/espressif/esp-idf/bl ... tif.c#L203

Please note that it might be problematic to pick the exact interface from user code if more interfaces point to the same subnet (might be a common usecase for WiFi + ethernet), it is however possible to override pre-route hooks in lwip, for details please check this comment https://github.com/espressif/esp-idf/is ... -519940878

Re: Selecting MQTT interface [IDF-1576]

Posted: Sat Apr 18, 2020 2:08 pm
by aderregibus
Thank you very much for your answer ESP_cermak.
Updating routing priorities should do the trick.

Re: Selecting MQTT interface [IDF-1576]

Posted: Sun Apr 19, 2020 12:07 pm
by axellin
ESP_cermak wrote:
Wed Apr 15, 2020 7:57 am
Hi aderregibus

lwIP uses the *default interface* for a socket to connect to, it is chosen based on user's API `netif_set_default()` provided the netif status is *up*.
There is a known issue regarding routing for ppp interface that needs fix:
https://github.com/espressif/esp-idf/issues/5069