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.
1
$ git clone https://github.com/eclipse/paho.mqtt.c.git
2
$ cd paho.mqtt.c/
3
$ git reset --hard 7e9b814bfb81d1edc32d8cef3594d5265ffb2395
Copied!
→ 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
1
$ vi src/samples/MQTTClient_publish.c +22
Copied!
→ Here give the ip address of board as below and save the file.
1
#define ADDRESS "tcp://192.168.1.39:1883"
Copied!
→ Same for subscribe file too
1
$ vi src/samples/MQTTClient_subscribe.c +22
Copied!
→ Here give the ip address of board as below
1
#define ADDRESS "tcp://192.168.1.39:1883"
Copied!
Step 4: Save and compile using below commands
1
$ make clean
2
$ make
Copied!
Step 5: After compilation, copy the libraries from below path to usr/lib in the board
1
$ build/output/libpaho-mqtt3*
Copied!
→ Copy the these two applications with name of "MQTTClient_subscribe", "MQTTClient_publish" from below path to "home/root" of the board.
1
$ build/output/samples/
Copied!
Step 6: Edit the mosquitto configuration file as below in the board
1
$ vi /etc/mosquitto/mosquitto.conf
Copied!
→ Add below lines in and save the file.
1
# Place your local configuration in /etc/mosquitto/conf.d/
2
#
3
# A full description of the configuration file is at
4
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example
5
listener 1883 192.168.1.39
Copied!
Note: here 1883 is port and 192.168.1.39 is board ip address.
Step 7: Run the below command in the board.
1
$ mosquitto -c /etc/mosquitto/mosquitto.conf &
Copied!
→ ssh to the board ip address as "ssh [email protected]" from your PC.
→ And run the below binary to get the data
1
./MQTTClient_subscribe
Copied!
→ Then run the below binary to sent the data in other terminal(do ssh to the board)
1
./MQTTClient_publish
Copied!

Below are the test logs for above commands:

Output logs of ./MQTTClient_subscribe:
1
[email protected]:~# ./MQTTClient_subscribe
2
Subscribing to topic MQTT Examples
3
for client ExampleClientSub using QoS1
4
5
Press Q<Enter> to quit
6
7
Message arrived
8
topic: MQTT Examples
9
message: Hello World!
Copied!
Output logs for ./MQTTClient_publish:
1
[email protected]:~# ./MQTTClient_publish
2
Waiting for up to 10 seconds for publication of Hello World!
3
on topic MQTT Examples for client with ClientID: ExampleClientPub
4
Message with delivery token 1 delivered
Copied!
Output logs of mosquitto -c /etc/mosquitto/mosquitto.conf command:
1
[email protected]:~# mosquitto -c /etc/mosquitto/mosquitto.conf
2
1325381603: mosquitto version 1.4.14 (build date 2020-11-04 14:08:01+0000) starting
3
1325381603: Config loaded from /etc/mosquitto/mosquitto.conf.
4
1325381603: Opening ipv4 listen socket on port 1883.
5
1325381610: New connection from 192.168.1.39 on port 1883.
6
1325381610: New client connected from 192.168.1.39 as ExampleClientPub (c1, k20).
7
1325381611: Client ExampleClientPub disconnected.
Copied!