Skip to content

Instantly share code, notes, and snippets.

View vasmani's full-sized avatar

Jihong Lee vasmani

View GitHub Profile
@vasmani
vasmani / MQTTSubscribe.sh
Created January 10, 2021 22:55 — forked from David-Lor/MQTTSubscribe.sh
Shell Script to subscribe to MQTT and execute a callback
#!/bin/bash
# This script subscribes to a MQTT topic using mosquitto_sub.
# On each message received, you can execute whatever you want.
while true # Keep an infinite loop to reconnect when connection lost/broker unavailable
do
mosquitto_sub -h "127.0.0.1" -t "test" | while read -r payload
do
# Here is the callback to execute whenever you receive a message: