Trouble with MQTT

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess

User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

Trouble with MQTT

Postby Tectu » Wed Feb 21, 2018 8:46 am

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.
https://ugfx.io - Embedded display and touchscreen library providing a full GUI Toolkit with full ChibiOS integration.

steved
Posts: 823
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 135 times

Re: Trouble with MQTT

Postby steved » Wed Feb 21, 2018 6:41 pm

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.

User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

Re: Trouble with MQTT

Postby Tectu » Mon Mar 05, 2018 2:58 pm

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.
https://ugfx.io - Embedded display and touchscreen library providing a full GUI Toolkit with full ChibiOS integration.

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Trouble with MQTT

Postby Giovanni » Mon Mar 05, 2018 3:36 pm

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


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 21 guests