Actions
Installation MQTT-Server (Broker) Mosquitto unter Debian¶
Pakete installieren¶
sudo apt install mosquitto mosquitto-clients
Konfiguration¶
/etc/mosquitto/mosquitto.conf
# Place your local configuration in /etc/mosquitto/conf.d/ # # A full description of the configuration file is at # /usr/share/doc/mosquitto/examples/mosquitto.conf.example pid_file /var/run/mosquitto.pid persistence true persistence_location /var/lib/mosquitto/ persistent_client_expiration 30d log_timestamp_format %Y-%m-%dT%H:%M:%S log_dest file /var/log/mosquitto/mosquitto.log include_dir /etc/mosquitto/conf.d
Im Verzeichnis /etc/mosquitto/conf.d werden die Konfigurationsdateien hinterlegt. Die Angaben in spitzen Klammern, wie <host> sind anzupassen, die Spitzen Klammern sind wegzulassen. Beispiel für eine Verbindung (Bridge) zu einem anderen Mosquitto-Broker:
/etc/mosquitto/conf.d/andino.conf
listener 1883 allow_anonymous true connection <bridge-name> address <host>:8883 bridge_cafile /etc/ssl/certs/ISRG_Root_X1.pem remote_username <username> remote_password <password> try_private true cleansession true # topic abc/def/# out 1 "" <prefix>/ # topic # in 1 <prefix>/ "" topic # both 1
Test¶
mosquitto_sub -h localhost -t '#' -v
Script zum Löschen von persistenten Daten¶
cleanmqtt.sh:
#!/bin/sh
# Clean mqtt from all retained messages.
# Usage: ./cleanmqtt hostname
# 2020-11-05 MG
echo "cleaning " $1 " :: usage: cleanmqtt <host>"
mosquitto_sub -h $1 -t "#" -v --retained-only | while read line
do
mosquitto_pub -h $1 -t "${line% *}" -r -n
done
Updated by Michael Gunsch about 2 years ago · 9 revisions