MQTT_SupportOnYocto - dhirajbennadi/ECEN5713-FinalProjectResources GitHub Wiki
Overview
The basic understanding of MQTT and support of MQTT On buildroot using Python libraries can be found on the following page: MQTT Buildroot Python Example
This page intends to cover the testing of a Publish-Subscribe mechanism on 2 clients using a MQTT Broker (Hive MQ) using Paho MQTT Library in C.
Build System
Yocto
Hardware
Raspberry Pi 3
Implementation Steps
-
Make the default configuration for Yocto image for raspberrypi3 (meta-openembedded, meta-raspberrypi and poky submodules are present)
-
Make sure the raspberry-pi is able to internet. Wifi Configuration
-
Adding the following packages in the core-image bb file IMAGE_INSTALL_append = " paho-mqtt-c
" -
Build an image and flash it on SD card.
-
Check if the following libraries are installed at the following location: usr/lib/
usr/lib/libpaho-mqtt3a.so.1.3.2: usr/lib/libpaho-mqtt3cs.so.1.3.2: usr/lib/libpaho-mqtt3as.so.1.3.2: usr/lib/libpaho-mqtt3c.so.1.3.2:
The version name might differ based on the board/time of installation
Testing with Code
To enable the communication between 2 clients using the Publish-Subscribe mechanism, an MQTT broker manages the communication. There are multiple MQTT Brokers available based on the use cases of the user. Brokers
I have used HiveMQ as my MQTT Broker. HiveMQ
Create a cluster on HiveMQ. Once the cluster is created the cloud information necessary to connect to the cluster are as follows.
- URL
- Port
- Network Sensitive Information - Username and Password
This information can be used to write an application for the publish and subscribe to Topics
A topic is a network channel through which the publisher publishes to and the cloud takes care of routing the network data to the subscribed channel over which the subscriber receives the data.
The basic test code is available at the following location in the Hive MQ Cluster.
Cluster -> Manage Cluster -> Getting Started
The above links would be available once the Cluster is created.
To compile the application code, the Makefile
would need the LD_FLAG = -lpaho-mqtt3cs
Testing on Ubuntu System
The basic code for publish and subscribe can be found at the following link: Code
Output
On one terminal the publish application is executed and on another subscribe application is executed.
Any message sent from the publisher is received at the subscriber end.