Skip to content

Instantly share code, notes, and snippets.

@PieGuy314
Last active November 1, 2023 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PieGuy314/b1bc6ecad400393d29474980090959c8 to your computer and use it in GitHub Desktop.
Save PieGuy314/b1bc6ecad400393d29474980090959c8 to your computer and use it in GitHub Desktop.
mqtt processing
#!/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