|
From: | Danny Con |
Subject: | [lwip-devel] MQTT unable to connect |
Date: | Wed, 19 May 2021 09:16:08 +0000 |
Hi, I hope someone recognizes my issue. I run an NXP platform (RT1064) with FreeRTOS. One task runs our application and one task runs lwIP with MQTT enabled. I noticed that if I disable MQTT, the TCP connection is stable, I can ping it forever,
however, when I enable MQTT and initialize it, the platform can only be pinged for about 20 seconds; then the lwIP stack seems to stop, see the call stack. In Wireshark I observe a lot of SYN retransmissions, I cannot explain this. The MQTT connection is never set up successfully, however, mqtt_client_connect() returns OK. Here is the MQTT part of my code, I followed the example: static mqtt_client_t clt; void Host_Comm_recv(void *pvParameters) // The FreeRTOS task { while (!Ethernet_stack_started()) { // Wait for the ethernet stack to get started. vTaskDelay(1); } mqtt_do_connect(&clt); //………… while (1) { //………… vTaskDelay(1); } } static void mqtt_do_connect(mqtt_client_t* client) { struct mqtt_connect_client_info_t ci; ip_addr_t ip_addr; ip_addr.addr = PP_HTONL(LWIP_MAKEU32(192, 168, 0, 101)); /* Setup an empty client info structure */ memset(&ci, 0, sizeof(ci)); /* Minimal amount of information required is client identifier, so set it here */ ci.client_id = "mqtt_test"; /* Initiate client and connect to server, if this fails immediately an error code is returned otherwise mqtt_connection_cb will be called with connection result after attempting to establish a connection with the server. For now MQTT version 3.1.1 is always used */ LOCK_TCPIP_CORE(); mqtt_client_connect(client, &ip_addr, MQTT_PORT, mqtt_connection_cb, 0, &ci); UNLOCK_TCPIP_CORE(); } static void mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection_status_t status) { err_t err; if (status == MQTT_CONNECT_ACCEPTED) { // This part is never reached… if (mqtt_client_is_connected(client)) { LOCK_TCPIP_CORE(); /* Setup callback for incoming publish requests */ mqtt_set_inpub_callback(client, mqtt_incoming_publish_cb, mqtt_incoming_data_cb, arg); /* Subscribe to a topic named "subtopic" with QoS level 1, call mqtt_sub_request_cb with result */ err = mqtt_subscribe(client, "subtopic", 1, mqtt_sub_request_cb, arg); UNLOCK_TCPIP_CORE(); if(err != ERR_OK) { volatile err_t e = err; (void)e; } } } else { /* Its more nice to be connected, so try to reconnect */ mqtt_do_connect(client); } } The call stack when a reconnect is attempted: Cremer_Base LinkServer Debug [C/C++ (NXP Semiconductors) MCU Application]
Cremer_Base.axf [MIMXRT1064xxxxA (cortex-m7)]
Thread #1 1 (Suspended : Breakpoint)
mqtt_connection_cb() at host_comm.c:159 0x700385fc
mqtt_close() at mqtt.c:565 0x7002b554
mqtt_tcp_err_cb() at mqtt.c:1.022 0x7002ba98
tcp_slowtmr() at tcp.c:1.413 0x700262ae
tcp_tmr() at tcp.c:242 0x700252b0
tcpip_tcp_timer() at timeouts.c:149 0x7002a490
sys_check_timeouts() at timeouts.c:390 0x7002a7a0
tcpip_timeouts_mbox_fetch() at tcpip.c:109 0x70053d0a
tcpip_thread() at tcpip.c:142 0x70032928
pxPortInitialiseStack() at port.c:216 0x70034c04
arm-none-eabi-gdb (8.3.0.20190709) The connection is closed on purpose because variable pcb_remove > 0. I don’t know what this means, but this seems the cause of the closed connection. I have a direct eth connection with another PC running the MQTT Broker, so no router is applied. I also attached the Wireshark log. Thanks in advance, Daan |
ws-dump.PNG
Description: ws-dump.PNG
[Prev in Thread] | Current Thread | [Next in Thread] |