MQTT Client on RB


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



  • Rugged Board A5d2x

  • ubuntu pc


  • Not Require


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
$ 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://"

→ Same for subscribe file too

$ vi src/samples/MQTTClient_subscribe.c +22

→ Here give the ip address of board as below

#define ADDRESS     "tcp://"

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

Note: here 1883 is port and 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@" from your PC.

→ And run the below binary to get the data


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


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

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 on port 1883.
1325381610: New client connected from as ExampleClientPub (c1, k20).
1325381611: Client ExampleClientPub disconnected.

Last updated