MQTT

Install mosquitto from https://mosquitto.org/ this is a broker that allows publishing and subscribing MQTT topics. It also comes with the command line tools for this purpose. Those tools can be used to access over the network MQTT broker.

Therefore running a MQTT broker on the local machine is not a must. In fact there is test.mosquitto.org a cloud based MQTT broker.

However having a MQTT broker on the local machine is recommended for developing and other purposes. For gentoo see https://wiki.gentoo.org/wiki/Mosquitto

/etc/mosquitto/mosquitto.conf is the configuration file and will run mosquitto as user mosquitto

systemctl start mosquitto to start the daemon

mosquitto_pub --help

mosquitto_pub -t <the topic> -m "<the message>" do this in one terminal -r would be retain so the broker stores the message and sends it to new appearing subscribers. Otherwise the new subscribers would get just the next message apearing in the future.

mosquitto_sub -t <the topic> -d -C 3 do this in an other terminal -d is debug and -C 3 exits it after 3 messages and -v would be verbose.

Repeat mosquitto_pub with other messages

When subscribing there are wild-cards for the topics:

+ to be used as <top>/+/<sub> all matching

# to be used as <top>/# every thing below

There is also QoS (Quality of Service) with is default value 0. Publishing and subscribing have separate QoS values.


Linurs startpage