MQTT and Mosquitto: Difference between revisions
Line 43: | Line 43: | ||
sudo service mosquitto restart | sudo service mosquitto restart | ||
== Test available messages == | |||
The mosquito_sub too allow display of messages, e.g.: | |||
mosquitto_sub -h localhost -t robobot/drive/# -d | |||
This will subscribe to messages from system '''robobot''', function '''drive''' and all topics in this function (the '#' is wildcard for the rest). | |||
The '''-d''' option is for debug and shows full topic and other information. | |||
The mosquitto_pub allow test messages to be send, e.g.: | |||
mosquitto_pub -h localhost -t robobot/drive/T0/go -m "3 3" -q 2 | |||
The message is "3 3" and the service quality 2 (send exactly 1 time) |
Latest revision as of 15:55, 5 December 2024
Back to Scorpi
Installation packages
On Raspberry PI 5 (running 64bit OS) Paho Mqtt can be installed with C++ support. This failed on Raspberry pi 4 (running 32 bit OK - due to Lidar support for YD Lidar S4B).
However, the C interface API works on Raspberry 32bit OS (Bullseye).
Install on 64bit OS:
sudo apt install libpaho-mqtt-dev libpaho-mqttpp-dev mosquitto-dev mosquitto-clients mosquitto
Install on 32bit OS:
sudo apt install libpaho-mqtt-dev mosquitto-dev mosquitto-clients mosquitto
- in addition to other packages required for normal compile
This should allow the teensy interface to compile.
Documentation MQTT API
For Paho-mqtt on Python, see https://eclipse.dev/paho/files/paho.mqtt.python/html/index.html
For C interface: https://eclipse.github.io/paho.mqtt.c/MQTTClient/html/index.html
For C++ see: https://eclipse.dev/paho/files/cppdoc/classmqtt_1_1client.html
Configure Mosquitto
Copy the full option list example to /etc/mosquitto/conf.d/:
sudo cp /usr/share/doc/mosquitto/examples/mosquitto.conf /etc/mosquitto/conf.d/
Uncomment and change in the 'listener' group:
#listener listener 1883
In the security group:
#allow_anonymous false allow_anonymous true
Restart mosquitto to take effect.
sudo service mosquitto restart
Test available messages
The mosquito_sub too allow display of messages, e.g.:
mosquitto_sub -h localhost -t robobot/drive/# -d
This will subscribe to messages from system robobot, function drive and all topics in this function (the '#' is wildcard for the rest).
The -d option is for debug and shows full topic and other information.
The mosquitto_pub allow test messages to be send, e.g.:
mosquitto_pub -h localhost -t robobot/drive/T0/go -m "3 3" -q 2
The message is "3 3" and the service quality 2 (send exactly 1 time)