MQTT connection issue with dual connection interface WiFi and Ethernet

lodogg
Posts: 7
Joined: Wed Sep 11, 2019 11:06 am

MQTT connection issue with dual connection interface WiFi and Ethernet

Postby lodogg » Fri Mar 08, 2024 2:30 pm

Good morning,
I am working on a project based on idf 5.2.1 and esp32-s3. The board is designed to have a dual connectivity interface with both WiFi and Ethernet. By setting the .route_prio parameter in the esp_netif_config_t structure, I assign priority to the two interfaces. In particular, I have configured Ethernet to be more prioritized than WiFi.
I have a simple MQTT application to test the connectivity.

If I start the system with Ethernet connected and WiFi configured, everything works correctly. The connection is established through Ethernet, and in case of disconnection of the cable, the connection switches automatically to WiFi.

If I start the board without the Ethernet cable connected, I expected the communication to occur through WiFi, but not everything works correctly. Essentially, the MQTT application seems to resolve the server's IP, but the connection times out.

While testing some solutions, I have also tried to change the interface used by MQTT once received the MQTT_EVENT_BEFORE_CONNECT assuming that the WiFi interface is "lo0"

Code: Select all

case MQTT_EVENT_BEFORE_CONNECT:
	struct ifreq ifr = {};
	strncpy(ifr.ifr_name, "lo0", sizeof(ifr.ifr_name));
	mqtt_cfg.network.if_name = 𝔦
	ESP_LOGI(TAG, "if_name = %s",ifr.ifr_name);
	mqtt_cfg.broker.address.uri = CONFIG_BROKER_URL;
	esp_mqtt_set_config(client, &mqtt_cfg);
break;
That is a little piece of the console output

I (11504) app_mqtt: MQTT_EVENT_BEFORE_CONNECT
D (11504) esp-tls: host:mqtt.eclipseprojects.io: strlen 23
I (11506) main_task: Returned from app_main()
I (11508) wifi:<ba-add>idx:0 (ifx:0, 64:66:b3:96:18:8e), tid:0, ssn:0, winSize:64
D (11510) wifi:eb is dhcp or dns sport = 5798, dport = 53
D (11538) esp-tls: [sock=54] Resolved IPv4 address: 137.135.83.217
D (11539) esp-tls: Bind [sock=54] to interface lo0
D (11539) esp-tls: [sock=54] Connecting to server. HOST: mqtt.eclipseprojects.io, Port: 1883
E (21542) esp-tls: [sock=54] select() timeout
E (21543) transport_base: Failed to open a new connection: 32774
E (21543) mqtt_client: Error transport connect
D (21543) event: running post MQTT_EVENTS:0 with handler 0x42009618 and context 0x3fcb76cc on loop 0x3fcb75cc
I (21544) app_mqtt: Event dispatched from event loop base=MQTT_EVENTS, event_id=0
I (21544) app_mqtt: MQTT_EVENT_ERROR

Who is online

Users browsing this forum: Baidu [Spider], MicroController and 108 guests