Last active
November 1, 2023 11:23
-
-
Save PieGuy314/b1bc6ecad400393d29474980090959c8 to your computer and use it in GitHub Desktop.
mqtt processing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Run as a background task | |
while true # Keep an infinite loop to reconnect when connection lost/broker unavailable | |
do | |
mosquitto_sub -h localhost -t mqtthost/message/\# -F "%t %p" | while read -r payload | |
do | |
# Here is the callback to execute whenever you receive a message: | |
topic=$(echo "$payload" | cut -d ' ' -f 1) | |
msg=$(echo "$payload" | cut -d ' ' -f 2-) | |
echo "Rx MQTT: $topic: ${msg}" | |
done | |
sleep 10 # Wait 10 seconds until reconnection | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment