Back to TILs

Mosquitto

Date: 2020-06-29Last modified: 2023-03-07

Introduction

Pros

Cons

Install server

sudo apt-get install mosquitto

Install client

sudo apt-get install mosquitto mosquitto-clients

Subscribe a topic

mosquitto_sub -t "test_topic"

Publish on topic

mosquitto_pub -t "test_topic" -m "HELLO WORLD!"

Testing the communication

Communication testing

Producer:

mosquitto_pub -t "test_topic" -m "HELLO WORLD!"
for i in {1..10}; do mosquitto_pub -t "test_topic" -m "I=$i"; done

Consumer:

mosquitto_sub -t "test_topic"
HELLO WORLD!
I=1
I=2
I=3
I=4
I=5
I=6
I=7
I=8
I=9
I=10

C++ and C library

sudo apt install libmosquitto-dev
or 
sudo apt install libpaho-mqtt-dev

References