MQTT Client Support


#1

is there any MQTT client library available to communicate with MQTT Broker like Mosquitto?
Example code will be more helpful.


Publishing data to MQTT broker
#2

Hi niladridm,

There is an existing app named MqttClient at http://github.com/mangOH/MqttClient however it has some problems. It was written in a way that is very specific to one use case involving the DataRouter at http://github.com/mangOH/DataRouter. I am working on a Legato app which will wrap the paho C mqtt library for Linux. It should be posted on github in a week or two.


#3

Hi David Frey,
Thank you. This is great. Hope paho c mqtt library will be available with the next Legato update for WP8548. It will be helpful if you share the expected release date.

Thanks


#4

I have pushed a new branch to https://github.com/mangOH/MqttClient named use_paho_linux_version. This branch implements a Legato app providing MQTT client services. I have published this as a branch because the mqtt.api file that it exposes is incompatible with the version of mqtt.api on the master branch. Because of the incompatibility, you will not be able to install any apps which depend on the master version of mqtt.api. DataRouter depends on MqttClient and ArduinoBridge depends on DataRouter, so you will need to make sure that neither of those is installed on your system.

The code is lightly tested. I have tried publishing and subscribing over an unencrypted connection. The underlying library supports SSL, but there is some additional work required to get that working.

Let me know if you find any issues.


#5

Thank you David,
In the readme file ( https://github.com/mangOH/MqttClient/tree/use_paho_linux_version ) it is mentioned that “paho.mqtt.c code must be built before you can invoke mksys”. I am new with the built process. It will be great if you guide me on this. Just gone through the readme file ( https://github.com/eclipse/paho.mqtt.c/tree/83cc318c96d508dd2ef26e87da23a858ff073b56 ) but not sure what I have to do

.


#6

If you have a command line based build environment setup for Legato development, then all you need to do is cd into the MqttClient folder and type make.

For more information on setting up your development environment, look here: http://mangoh.io/getting-started.html


#7

Thanks.
I just follow the steps mentioned in the CLI document able to play with helloWorld application. But getting below error to build MqttClient app.
blackpanther@blackpanther-ubunty:~$ cd MqttClient/
blackpanther@blackpanther-ubunty:~/MqttClient$ make wp85
export TARGET=wp85 ;
mkapp -v -t wp85
mqttClient.adef
Command-line arguments from previous run not found.
Parsing file: ‘/home/blackpanther/MqttClient/mqttClient.adef’.
Modelling application: 'mqttClient’
defined in: ‘/home/blackpanther/MqttClient/mqttClient.adef’
** ERROR:
/home/blackpanther/MqttClient/mqttClient.adef:9:8: error: File not found: '/home/blackpanther/MqttClient/paho.mqtt.c/build/output/libpaho-mqtt3cs.so’
make: *** [wp85] Error 1

and it is because of paho.mqtt.c folder is empty so i have download the file from https://github.com/eclipse/paho.mqtt.c/tree/83cc318c96d508dd2ef26e87da23a858ff073b56 but still getting the same error. May be i have to build paho.mqtt.c as well. please guide me on this


#8

I believe your paho.mqtt.c directory is probably empty because the git submodule was not fetched when you cloned MqttClient. In future, if you are cloning a repository which uses submodules, you can do git clone --recurse-submodules https://git/repository/url. Since you have already cloned MqttClient, you should be able to do git submodule init && git submodule update to pull in the paho code.


#9

Thank you.
Yes i have done the same but still getting file not found error because “output/libpaho-mqtt3cs.so” file is missing inside "/paho.mqtt.c/build/ " (please look into the attached image)

/MqttClient/paho.mqtt.c/build/output/libpaho-mqtt3cs.so’
make: *** [wp85] Error 1


#10

any clue how to proceed further.
Thanks


#11

What happens when you run make in the paho.mqtt.c folder? Does it appear to build correctly?


#12

Hi
Yes i am able to build paho.mqtt.c
but when trying to build MqttClient I am getting below error

FAILED: /home/niladri/legato/packages/legato.toolchain.1.7.3.fw_SWI9X15Y_07100400-wp85-native-x86_64-201606090913/resources/native/wrapper/arm-poky-linux-gnueabi-gcc --sysroot=/home/niladri/legato/packages/legato.toolchain.1.7.3.fw_SWI9X15Y_07100400-wp85-native-x86_64-201606090913/resources/native/sysroots/armv7a-vfp-neon-poky-linux-gnueabi -shared -o _build_mqttClient/wp85/staging/read-only/lib/libComponent_mqttClientService.so _build_mqttClient/wp85/component/e5f23a1bb4f0e8bc9b47224bdbfd5513/obj/63ec8c8e3eac8401b608d55d158ad83c.o _build_mqttClient/wp85/api/c75963def1a6456e8668e082dc056809/server/mqtt_server.o _build_mqttClient/wp85/component/e5f23a1bb4f0e8bc9b47224bdbfd5513/obj/_componentMain.c.o -L/home/niladri/legato/packages/legato.framework.16.4.0.I201606090927/resources/legato/apps/sample/MqttClient/paho.mqtt.c/build/output -lpaho-mqtt3cs -L_build_mqttClient/wp85/staging/read-only/lib -Wl,–enable-new-dtags,-rpath="$ORIGIN/…/lib" “-L$LEGATO_BUILD/framework/lib” -llegato -lpthread -lrt -lm
/home/niladri/legato/packages/legato.framework.16.4.0.I201606090927/resources/legato/apps/sample/MqttClient/paho.mqtt.c/build/output/libpaho-mqtt3cs.so: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
make: *** [wp85] Error 1

Please help

Thanks
Niladri


#13

Did you build paho.mqtt.c with the cross compilation toolchain for the WP85?


#14

Yes this might be the issue.
It will be great if you can share how to build paho.mqtt.c with the cross compilation toolchain for the WP85


#15

I think this should work:

$ cd paho.mqtt.c
$ export CC=/opt/swi/y17-ext/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc
$ make

#16

Thanks
Now i am getting below error!
blackpanther@blackpanther-ubunty:~/paho.mqtt.c$ export CC=/opt/swi/y17-ext/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc

blackpanther@blackpanther-ubunty:~/paho.mqtt.c$ make
mkdir -p build/output/samples
mkdir -p build/output/test
echo OSTYPE is Linux
OSTYPE is Linux
/opt/swi/y17-ext/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -g -fPIC -Os -Wall -fvisibility=hidden -Ibuild -o build/output/libpaho-mqtt3c.so.1.0 src/Clients.c src/Heap.c src/LinkedList.c src/Log.c src/Messages.c src/MQTTClient.c src/MQTTPacket.c src/MQTTPacketOut.c src/MQTTPersistence.c src/MQTTPersistenceDefault.c src/MQTTProtocolClient.c src/MQTTProtocolOut.c src/SocketBuffer.c src/Socket.c src/StackTrace.c src/Thread.c src/Tree.c src/utf-8.c -shared -Wl,-init,MQTTClient_init -lpthread -Wl,-soname,libpaho-mqtt3c.so.1
make: /opt/swi/y17-ext/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc: Command not found
make: *** [build/output/libpaho-mqtt3c.so.1.0] Error 127


#17

It seems like you don’t have the toolchain installed in that directory. Can you look in /opt/swi and see if anything is there? I’m not really familiar with where Developer Studio puts the toolchain, so if you did an IDE based setup of your tools then perhaps they are somewhere else. If all else fails, try searching for the gcc binary. find / -type f -name 'arm-poky-linux-gnueabi-gcc' 2>/dev/null.


#18

Thank you David for your quick response.
Yes now i am able to find out the path of 'arm-poky-linux-gnueabi-gcc’
Now getting below error. don’t know why.

mkdir -p build/output/samples
mkdir -p build/output/test
echo OSTYPE is Linux
OSTYPE is Linux
/home/blackpanther/legato/packages/legato.toolchain.1.7.3.fw_SWI9X15Y_07100400-wp85-native-x86_64-201606090913/resources/native/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -g -fPIC -Os -Wall -fvisibility=hidden -Ibuild -o build/output/libpaho-mqtt3c.so.1.0 src/Clients.c src/Heap.c src/LinkedList.c src/Log.c src/Messages.c src/MQTTClient.c src/MQTTPacket.c src/MQTTPacketOut.c src/MQTTPersistence.c src/MQTTPersistenceDefault.c src/MQTTProtocolClient.c src/MQTTProtocolOut.c src/SocketBuffer.c src/Socket.c src/StackTrace.c src/Thread.c src/Tree.c src/utf-8.c -shared -Wl,-init,MQTTClient_init -lpthread -Wl,-soname,libpaho-mqtt3c.so.1
In file included from src/Clients.c:24:0:
src/Clients.h:22:18: fatal error: time.h: No such file or directory
#include <time.h>
^
compilation terminated.
In file included from src/Heap.c:29:0:
src/Tree.h:21:45: fatal error: stdlib.h: No such file or directory
#include <stdlib.h> // for size_t definition
^
compilation terminated.
In file included from src/LinkedList.c:27:0:
src/LinkedList.h:22:45: fatal error: stdlib.h: No such file or directory
#include <stdlib.h> // for size_t definition
^
compilation terminated.
In file included from src/MQTTPacket.h:22:0,
from src/Log.c:27:
src/Socket.h:21:23: fatal error: sys/types.h: No such file or directory
#include <sys/types.h>
^
compilation terminated.
src/Messages.c:27:19: fatal error: stdio.h: No such file or directory
#include <stdio.h>
^
compilation terminated.
src/MQTTClient.c:41:20: fatal error: stdlib.h: No such file or directory
#include <stdlib.h>
^
compilation terminated.
In file included from src/MQTTPacket.h:22:0,
from src/MQTTPacket.c:26:
src/Socket.h:21:23: fatal error: sys/types.h: No such file or directory
#include <sys/types.h>
^
compilation terminated.
In file included from src/MQTTPacket.h:22:0,
from src/MQTTPacketOut.h:22,
from src/MQTTPacketOut.c:28:
src/Socket.h:21:23: fatal error: sys/types.h: No such file or directory
#include <sys/types.h>
^
compilation terminated.
src/MQTTPersistence.c:25:19: fatal error: stdio.h: No such file or directory
#include <stdio.h>
^
compilation terminated.
src/MQTTPersistenceDefault.c:32:19: fatal error: stdio.h: No such file or directory
#include <stdio.h>
^
compilation terminated.
src/MQTTProtocolClient.c:30:20: fatal error: stdlib.h: No such file or directory
#include <stdlib.h>
^
compilation terminated.
src/MQTTProtocolOut.c:29:20: fatal error: stdlib.h: No such file or directory
#include <stdlib.h>
^
compilation terminated.
In file included from src/SocketBuffer.c:24:0:
src/SocketBuffer.h:24:24: fatal error: sys/socket.h: No such file or directory
#include <sys/socket.h>
^
compilation terminated.
In file included from src/Socket.c:27:0:
src/Socket.h:21:23: fatal error: sys/types.h: No such file or directory
#include <sys/types.h>
^
compilation terminated.
In file included from src/StackTrace.c:17:0:
src/StackTrace.h:20:19: fatal error: stdio.h: No such file or directory
#include <stdio.h>
^
compilation terminated.
In file included from src/Thread.c:28:0:
src/Thread.h:32:22: fatal error: pthread.h: No such file or directory
#include <pthread.h>
^
compilation terminated.
In file included from src/Tree.c:26:0:
src/Tree.h:21:45: fatal error: stdlib.h: No such file or directory
#include <stdlib.h> // for size_t definition
^
compilation terminated.
src/utf-8.c:27:20: fatal error: stdlib.h: No such file or directory
#include <stdlib.h>
^
compilation terminated.
make: *** [build/output/libpaho-mqtt3c.so.1.0] Error 1


#19

Hi
ooops! the problem is in the toolchain. I have installed the Linux toolchain again and now i am able to built the project properly. Thanks for all your help.

Thanks


#20

Hi David,
Yes the application is working as expected. I am able to publish / subscribe data using our own MQTT broker.

Thanks