Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # Simple Script to remove all reatined messages for a homie device
- # Works great for me to get rid of devices in MQTT, which are not active anymore.
- # Maybe it is helpful for someone else...
- echo
- echo "Clearing for device $1 all messages, last clean will block kill with Ctrl+C when nothing happens anymore."
- echo
- #mosquitto_sub -v -h 10.0.2.2 -t "homie/$1/#" -C $2
- echo "STARTING :: Checking for valid topics one after the other...."
- MAX_TOPICS_TO_CHECK=100
- for c in `seq 0 $MAX_TOPICS_TO_CHECK`
- do
- echo " $c Checking for Topic ...."
- for i in `mosquitto_sub -v -h 10.0.2.2 -t "homie/$1/#" -C 1|cut -d' ' -f1`
- do
- # echo "mosquitto_pub -h 10.0.2.2 -r -n -t \"`echo $i | sed s#'\\$'#'\\\\\\\$'#g`\""
- echo " $i >> sending empty payload to topic with retained flag"
- mosquitto_pub -h 10.0.2.2 -r -n -t "`echo $i | sed s#'\\$'#'\\\$'#g`"
- done
- done
Add Comment
Please, Sign In to add comment