MQTT Client on RB

Objective:

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

Materials:

Hardware:

  • Rugged Board A5d2x

  • 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 a5d2x 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.1.39: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.1.39: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.1.39

Note: here 1883 is port and 192.168.1.39 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.1.39" 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@rugged-board-a5d2x-sd1:~# ./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@rugged-board-a5d2x-sd1:~# ./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@rugged-board-a5d2x-sd1:~#

Output logs of mosquitto -c /etc/mosquitto/mosquitto.conf command:

root@rugged-board-a5d2x-sd1:~# mosquitto -c /etc/mosquitto/mosquitto.conf 
1325381603: mosquitto version 1.4.14 (build date 2020-11-04 14:08:01+0000) starting
1325381603: Config loaded from /etc/mosquitto/mosquitto.conf.
1325381603: Opening ipv4 listen socket on port 1883.
1325381610: New connection from 192.168.1.39 on port 1883.
1325381610: New client connected from 192.168.1.39 as ExampleClientPub (c1, k20).
1325381611: Client ExampleClientPub disconnected.

Last updated