Page 1 of 1

Trouble with MQTT

Posted: Wed Feb 21, 2018 8:46 am
by Tectu
Hello folks!

I'm currently preparing a little demo where I use ChibiOS 18.2.0 with LwIP 2.0.3 (the one that comes with ChibiOS) on an STM32F407 microcontroller. I managed to get the ChibiOS LwIP demo (HTTP server) running without any problems. I also managed to send raw data over TCP myself without any problems.
For this application I need to run MQTT. LwIP 2.0.3 already comes with a built-in MQTT client which seems very suitable.

The first problem I encountered is that I needed to modify the /os/various/lwip_bindings/lwip.mk file. Whenever I compiled the MQTT example code that comes with LwIP I got a couple of undefined reference linking errors. I had to add $(MQTTFILES) to LWSRC:

Code: Select all

LWSRC = $(COREFILES) $(CORE4FILES) $(APIFILES) $(LWBINDSRC) $(NETIFFILES) $(HTTPDFILES) $(MQTTFILES)

Looking at the LwIP makefile (/lwip/src/Filelist.mk) it seems that the more appropriate solution is to include $(LWIPAPPFILES) instead of all the single ones.
What's the story on this? Did nobody ever run MQTT and therefore nobody ever reported this issue or is this by design?

Once I managed to compile and run the code I ran into the problem that I can't connect to my MQTT message broker ("the server"). I tried various different MQTT message brokers (both private and public ones) and I always get the same effect: mqtt_client_connect() returns without any error, but the mqtt_connection_cb() callback always gets the state DISCONNECTED back. I tried to debug this and when I look at the mqtt client struct the conn_status is set to MQTT_CONNECT_REFUSED_PROTOCOL_VERSION.
I'm very confused by this as LwIP claims to always run MQTT 3.1.1 and the brokers I used support both 3.1 and 3.1.1. Also I wrote programs (for a desktop computer system) that can successfully connect to all those brokers. I'm not using LwIP there - the test was just to confirm that there's no networking / infrastructure problem.

Does anybody have any idea about this? My main question is whether this might have something to do with the ChibiOS integration/bindings. Is it possible that something is missing in the LwIP thread that is defined in the ChibiOS bindings which gets started upon calling lwipInit()?

I'd appreciate any kind of help here.

Re: Trouble with MQTT

Posted: Wed Feb 21, 2018 6:41 pm
by steved
I'd be surprised if the problem is Chibi-specific; really MQTT is a layer on top of the basic tcp/ip services, which seem to work well.
Given that there doesn't seem to be a supporting example, its possible the MQTT driver isn't well-tested.

Its possible there are some options to configure; this isn't always obvious with lwIp until you start digging (and there seem to be a lot of options!).

It's on my list of things to play with, but unlikely to get to the top for a while.

Re: Trouble with MQTT

Posted: Mon Mar 05, 2018 2:58 pm
by Tectu
Thank you for your reply, steved, much appreciated!

I managed to get MQTT running. There was an issue with one of the timeout settings of LwIP (just like you said!).

However, I definitely needed to modify the ChibiOS bindings makefile as mentioned in my first post.
@Giovanni: Is this something you left out on purpose? It's of course also possible to add $(MQTTFILES) in the application Makefile.

Re: Trouble with MQTT

Posted: Mon Mar 05, 2018 3:36 pm
by Giovanni
Hi,

Is it a good idea to include everything even if not used? the idea is that the user should trim the makefile for its own application.

Giovanni