cancel
Showing results for 
Search instead for 
Did you mean: 

Paho MQTT : connexion aborted by STM32

tarzan2
Associate III

Hello,

I'm trying to implement the lwip + paho mqtt (embedded version) on a nucleo-f207zg board, following this project : 

https://blog.naver.com/eziya76/221938551688 

I have a mosquitto broker and wireshark on a windows computer.

Mosquitto started with command :

mosquitto -v -c broker.cfg

broker.cfg file content :

listener 1883
allow_anonymous true

Windows IP : 192.168.1.105

STM32 IP : 192.168.1.200

Both IP are static. The ETH link is ok, I can ping the STM32. I'm blocked since a few day on the connection to the MQTT broker.

ConnectNetwork() works, but MQTTConnect() don't.

The STM32 send the request, mosquitto receive it and CONNACK but the STM32 don't received it and abort the connection.

mosquitto.png

wireshark.png

I think I have localized the issue, but I can't resolve it with my limited knowledge in network programming.

MqttConnectBroker() => MQTTConnect() => MQTTConnectWithResults() 

This function make the following call to waitfor() :

    ret = waitfor(c, CONNACK, &connect_timer);
    if (ret == CONNACK)
    {
        data->rc = 0;
        data->sessionPresent = 0;
        if (MQTTDeserialize_connack(&data->sessionPresent, &data->rc, c->readbuf, c->readbuf_size) == 1)
            rc = data->rc;
        else
            rc = FAILURE;
    }
    else
    {
        rc = FAILURE;
    }

waitfor() always return -1. Looking into this function :

int waitfor(MQTTClient* c, int packet_type, Timer* timer)
{
    int rc = FAILURE;

    do
    {
        if (TimerIsExpired(timer))
            break; // we timed out
        rc = cycle(c, timer);
    }
    while (rc != packet_type && rc >= 0);

    return rc;
}

There is no timeout, but cycle() returns -1. 

int cycle(MQTTClient* c, Timer* timer)
{
    int len = 0,
        rc = MQTT_SUCCESS;

    int packet_type = readPacket(c, timer);     /* read the socket, see what work is due */

    switch (packet_type)
    {
        default:
            /* no more data to read, unrecoverable. Or read packet fails due to unexpected network error */
            rc = packet_type;
            goto exit;

packet_type = -1, so I always go to the default case, exit with an error code making the STM32 disconnect from the host.

I also have a SWV trace with LWIP debug + some high level debug (see below)

Any help will be strongly appreciated :)

Thanks

SWV ITM Data Console - ITM Port: 0
Don't remove this printf to prevent hard fault.
Hello
netif: netmask of interface    set to 255.255.255.0
netif: GW address of interface    set to 192.168.1.1
netif_set_ipaddr: netif address being changed
netif: IP address of interface    set to 192.168.1.200
etharp_timer
netif: added interface st IP addr 192.168.1.200 netmask 255.255.255.0 gw 192.168.1.1
netif: setting default interface st
etharp_request: sending ARP request.
pbuf_alloc(length=28)
pbuf_alloc(length=28) == 0x200091ac
etharp_raw: sending raw ARP packet.
pbuf_header: old 0x200091cc new 0x200091be (14)
ethernet_output: sending packet 0x200091ac
pbuf_free(0x200091ac)
pbuf_free: deallocating 0x200091ac
DHCP/Static IP O.K.
lwip_socket(PF_INET, SOCK_STREAM, 0) = 0
lwip_connect(0, addr=192.168.1.105 port=1883)
tcp_connect to port 1883
pbuf_alloc(length=4)
pbuf_alloc(length=4) == 0x200091ac
pbuf_header: old 0x200091f4 new 0x200091e0 (20)
pbuf_header: old 0x200091e0 new 0x200091cc (20)
ip4_output_if: st0
IP header:
+-------------------------------+
| 4 | 5 |  0x00 |        44     | (v, hl, tos, len)
+-------------------------------+
|        0      |000|       0   | (id, flags, offset)
+-------------------------------+
|  255  |    6  |    0x0000     | (ttl, proto, chksum)
+-------------------------------+
|  192  |  168  |    1  |  200  | (src)
+-------------------------------+
|  192  |  168  |    1  |  105  | (dest)
+-------------------------------+
ip4_output_if: call netif->output()
etharp_find_entry: found empty entry 0
etharp_find_entry: selecting empty entry 0
etharp_request: sending ARP request.
pbuf_alloc(length=28)
pbuf_alloc(length=28) == 0x20009200
etharp_raw: sending raw ARP packet.
pbuf_header: old 0x20009220 new 0x20009212 (14)
ethernet_output: sending packet 0x20009200
pbuf_free(0x20009200)
pbuf_free: deallocating 0x20009200
pbuf_alloc(length=44)
pbuf_alloc(length=44) == 0x20009200
pbuf_copy(0x20009200, 0x200091ac)
pbuf_copy: end of chain reached.
etharp_query: queued packet 0x200091ac on ARP entry 0
tcp_slowtmr: processing active pcb
tcp_slowtmr: processing active pcb
tcp_slowtmr: polling application
etharp_timer
etharp_request: sending ARP request.
pbuf_alloc(length=28)
pbuf_alloc(length=28) == 0x20009254
etharp_raw: sending raw ARP packet.
pbuf_header: old 0x20009274 new 0x20009266 (14)
ethernet_output: sending packet 0x20009254
pbuf_free(0x20009254)
pbuf_free: deallocating 0x20009254
pbuf_alloc(length=60)
pbuf_alloc: allocated pbuf 0x2000c6b4
pbuf_alloc(length=60) == 0x2000c6b4
tcpip_thread: PACKET 0x2000a1b0
ethernet_input: dest:0hx:0hx:0hx:0hx:0hx:0hx, src:0hx:0hx:0hx:0hx:0hx:0hx, type:0
pbuf_header: old 0x2000c6c4 new 0x2000c6d2 (-14)
etharp_update_arp_entry: 192.168.1.105 - 18:c0:4d:ea:ea:6a
etharp_find_entry: found matching entry 0
etharp_update_arp_entry: updating stable entry 0
pbuf_header: old 0x20009220 new 0x20009212 (14)
ethernet_output: sending packet 0x20009200
pbuf_free(0x20009200)
pbuf_free: deallocating 0x20009200
etharp_input: incoming ARP reply
pbuf_free(0x2000c6b4)
pbuf_free: deallocating 0x2000c6b4
pbuf_alloc(length=60)
pbuf_alloc: allocated pbuf 0x2000c6b4
pbuf_alloc(length=60) == 0x2000c6b4
tcpip_thread: PACKET 0x2000a1b0
ethernet_input: dest:0hx:0hx:0hx:0hx:0hx:0hx, src:0hx:0hx:0hx:0hx:0hx:0hx, type:0
pbuf_header: old 0x2000c6c4 new 0x2000c6d2 (-14)
ip_input: iphdr->dest 0xc801a8c0 netif->ip_addr 0xc801a8c0 (0x1a8c0, 0x1a8c0, 0xc8000000)
ip4_input: packet accepted on interface st
ip4_input: 
IP header:
+-------------------------------+
| 4 | 5 |  0x00 |        44     | (v, hl, tos, len)
+-------------------------------+
|    34004      |010|       0   | (id, flags, offset)
+-------------------------------+
|  128  |    6  |    0xf175     | (ttl, proto, chksum)
+-------------------------------+
|  192  |  168  |    1  |  105  | (src)
+-------------------------------+
|  192  |  168  |    1  |  200  | (dest)
+-------------------------------+
ip4_input: p->len 44 p->tot_len 44
pbuf_header: old 0x2000c6d2 new 0x2000c6e6 (-20)
pbuf_header: old 0x2000c6e6 new 0x2000c6fe (-24)
pbuf_free(0x200091ac)
pbuf_free: deallocating 0x200091ac
pbuf_alloc(length=20)
pbuf_alloc(length=20) == 0x200091ac
pbuf_header: old 0x200091e0 new 0x200091cc (20)
ip4_output_if: st0
IP header:
+-------------------------------+
| 4 | 5 |  0x00 |        40     | (v, hl, tos, len)
+-------------------------------+
|        1      |000|       0   | (id, flags, offset)
+-------------------------------+
|  255  |    6  |    0x0000     | (ttl, proto, chksum)
+-------------------------------+
|  192  |  168  |    1  |  200  | (src)
+-------------------------------+
|  192  |  168  |    1  |  105  | (dest)
+-------------------------------+
ip4_output_if: call netif->output()
pbuf_header: old 0x200091cc new 0x200091be (14)
ethernet_output: sending packet 0x200091ac
pbuf_free(0x200091ac)
pbuf_free: deallocating 0x200091ac
pbuf_free(0x2000c6b4)
pbuf_free: deallocating 0x2000c6b4
lwip_connect(0) succeeded
ConnectNetwork ok.
lwip_send(0, data=0x20000158, size=34, flags=0x0)
pbuf_alloc(length=34)
pbuf_alloc(lengtif: call netif->output()
pbuf_header: old 0x200091cc new 0x200091be (14)
ethernet_output: sending packet 0x200091ac
lwip_send(0) err=0 written=34pbuf_alloc(length=60)
pbuf_alloc: allocated pbuf 0x2000c6b4
pbuf_alloc(length=60) == 0x2000c6b4
tcpip_thread: PACKET 0x2000a1b0
ethernet_input: dest:0hx:0hx:0hx:0hx:0hx:0hx, src:0hx:0hx:0hx:0hx:0
lwip_ioctl(0, UNIMPL: 0x4004667f, 0x200087bc)
MQTTConnect failed.
1 ACCEPTED SOLUTION

Accepted Solutions
tarzan2
Associate III

Solved !

LWIP_SO_RCVBUF was not enabled...

View solution in original post

1 REPLY 1
tarzan2
Associate III

Solved !

LWIP_SO_RCVBUF was not enabled...