MQTT Client on RB

Objective:

This guide describes the testing method of mqtt client for the Rugged Board i.MX6UL.

Materials:

Hardware:

  • Rugged Board i.MX6UL

  • ubuntu pc

Software:

  • Not Require

Procedure:

Step 1: Add the below additional packages in yocto and use compiled rootfs.

  • mosquitto

  • tcpdump

Step 2: Download the source from below link and cross compile it.

$ git clone https://github.com/eclipse/paho.mqtt.c.git
$ cd paho.mqtt.c/
$ git reset --hard 7e9b814bfb81d1edc32d8cef3594d5265ffb2395

→ Run the toolchain of rugged board i.mx6ul to cross compile the application source.

Step 3: Edit the publish and subscribe files of mqtt applications as below

$ vi src/samples/MQTTClient_publish.c +22

→ Here give the ip address of board as below and save the file.

#define ADDRESS     "tcp://192.168.3.11:1883"

→ Same for subscribe file too

$ vi src/samples/MQTTClient_subscribe.c +22

→ Here give the ip address of board as below

#define ADDRESS     "tcp://192.168.3.11:1883"

Step 4: Save and compile using below commands

$ make clean
$ make

Step 5: After compilation, copy the libraries from below path to usr/lib in the board

$ build/output/libpaho-mqtt3*

→ Copy the these two applications with name of "MQTTClient_subscribe", "MQTTClient_publish" from below path to "home/root" of the board.

$ build/output/samples/

Step 6: Edit the mosquitto configuration file as below in the board

$ vi /etc/mosquitto/mosquitto.conf

→ Add below lines in and save the file.

# Place your local configuration in /etc/mosquitto/conf.d/
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example
listener 1883 192.168.3.11

Note: here 1883 is port and 192.168.3.11 is board ip address.

Step 7: Run the below command in the board.

$ mosquitto -c /etc/mosquitto/mosquitto.conf &

→ ssh to the board ip address as "ssh root@192.168.3.11" from your PC.

→ And run the below binary to get the data

./MQTTClient_subscribe

→ Then run the below binary to sent the data in other terminal(do ssh to the board)

./MQTTClient_publish

Below are the test logs for above commands:

Output logs of ./MQTTClient_subscribe:

root@ruggedboard-imx6ul:~# ./MQTTClient_subscribe
Subscribing to topic MQTT Examples
for client ExampleClientSub using QoS1
 
Press Q<Enter> to quit
 
Message arrived
     topic: MQTT Examples
   message: Hello World!

Output logs for ./MQTTClient_publish:

root@ruggedboard-imx6ul:~# ./MQTTClient_publish 
Waiting for up to 10 seconds for publication of Hello World!
on topic MQTT Examples for client with ClientID: ExampleClientPub
Message with delivery token 1 delivered
root@ruggedboard-imx6ul:~#

Last updated