Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # This script subscribes to a MQTT topic using mosquitto_sub.
  4. # On each message received, you can execute whatever you want.
  5.  
  6. while true # Keep an infinite loop to reconnect when connection lost/broker unavailable
  7. do
  8. mosquitto_sub -h "127.0.0.1" -t "test" | while read -r payload
  9. do
  10. # Here is the callback to execute whenever you receive a message:
  11. echo "Rx MQTT: ${payload}"
  12. done
  13. sleep 10 # Wait 10 seconds until reconnection
  14. done # & # Discomment the & to run in background (but you should rather run THIS script in background)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement