Mosquitto
Date: 2020-06-29Last modified: 2023-03-07
Introduction
- MQTT is a very lightweight messaging protocol
- Specifically designed for machine-to-machine telemetry
- The MQTT protocol is based on a TCP connection.
- IBM Watson uses MQTT to allow it to communicate with devices.
Pros
- Lightweight and efficient—which means it’s optimal for small bandwidth environments such as microcontrollers
- Bi-directional communications
- Messages are encrypted using TLS
- Offers support for unreliable networks using persistent sessions
Cons
- Doesn’t support video streaming
- Messages are transmitted asynchronously
- Can experience issues with latency and speed.
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
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
- 8 Most Popular Instant Messaging & Chat Protocols
- Everything About MQTT Protocol — Message Queue Telemetry Transport
- How to Install and Secure the Mosquitto MQTT Messaging Broker on Ubuntu 16.04
- How to Install and Secure the Mosquitto MQTT Messaging Broker on Debian 8
- Mosquitto C++ sample code to publish message
- Eclipse Paho MQTT C++ Client Library
- https://github.com/eclipse/paho.mqtt.cpp/tree/master/src/samples
- libmosquittopp - sample client hangs on loop_stop() method
- https://medium.com/tht-things-hackers-team/instalar-mqtt-broker-no-linux-debian-ubuntu-f8861da70ef6
- https://android.developreference.com/article/16161720/libmosquittopp+-+sample+client+hangs+on+loop_stop()+method