Selecting MQTT interface [IDF-1576]

aderregibus
Posts: 4
Joined: Mon Apr 13, 2020 6:36 pm

Selecting MQTT interface [IDF-1576]

Postby aderregibus » Mon Apr 13, 2020 6:44 pm

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!

ESP_Alvin
Posts: 211
Joined: Thu May 17, 2018 2:26 am

Re: Selecting MQTT interface [IDF-1576]

Postby ESP_Alvin » Tue Apr 14, 2020 3:05 am

Moderator's note: edit the topic title for issue tracking, thanks.

Thanks for the suggestion, we will evaluate, thanks.

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

Re: Selecting MQTT interface [IDF-1576]

Postby ESP_cermak » 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*.
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

aderregibus
Posts: 4
Joined: Mon Apr 13, 2020 6:36 pm

Re: Selecting MQTT interface [IDF-1576]

Postby aderregibus » Sat Apr 18, 2020 2:08 pm

Thank you very much for your answer ESP_cermak.
Updating routing priorities should do the trick.

axellin
Posts: 200
Joined: Mon Sep 17, 2018 9:09 am

Re: Selecting MQTT interface [IDF-1576]

Postby axellin » Sun Apr 19, 2020 12:07 pm

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

Who is online

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