Hello,
I'm using the latest lwip stable release 2.13 on STM32F4 target and trying to establish a MQTT connection.
I'm setting up the network interface as follow
lwip_init();
netif_add(&my_netif, &myIP, &maskIP, &gwIP, NULL, netif_init_, netif_input);
netif_set_default(&my_netif);
netif_set_up(&my_netif);
And then calling MQTT as in the example from Dirk Ziegelmeier
mqtt_client = mqtt_client_new();
mqtt_set_inpub_callback(mqtt_client,
mqtt_incoming_publish_cb,
mqtt_incoming_data_cb,
LWIP_CONST_CAST(void*, &mqtt_client_info));
mqtt_client_connect(mqtt_client,
&mqtt_ip, MQTT_PORT,
mqtt_connection_cb, LWIP_CONST_CAST(void*, &mqtt_client_info),
&mqtt_client_info);
This returns ERR_RTE ( Routing problem.)
The error is happening in mqtt_client_connect()
When reading the code I couldn't find any binding between TCP stack ( created in mqtt_client_connect()) and the netif ?
So I added the binding in mqtt_client_connect() in mqtt.c
struct tcp_pcb *pcb;
pcb = (struct tcp_pcb *)client->conn->state;
tcp_bind_to_default_netif(pcb);
Just before
/* Connect to server */
err = altcp_connect(client->conn, ip_addr, port, mqtt_tcp_connect_cb);
tcp_bind_to_default_netif() in tcp.c
void tcp_bind_to_default_netif(struct tcp_pcb *pcb)
{
LWIP_ASSERT_CORE_LOCKED();
if (netif_default != NULL) {
pcb->netif_idx = netif_get_index(netif_default);
} else {
pcb->netif_idx = NETIF_NO_INDEX;
}
}
Now I don't have the routing error and mqtt_client_connect() is exiting without any errors but no connection to my MQTT broker.
I'm not sure where the tcp and netif binding should be done ?
Any suggestions are very welcome
Thank you,
Chaabane