Last active
June 28, 2017 08:33
-
-
Save hallgren/c68e0cb648e2abc701b85f483d5902e9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/ash | |
# MQTT SETTINGS | |
host="<mqtt_broker_url>" | |
user="<user>" | |
password="<password>" | |
port=1883 | |
topic="<topic>" | |
#ONION OMEGA2 GPIO PID SETTING | |
io_pid=0 | |
gpioctl dirout $io_pid > /dev/null | |
p="backpipe" | |
ctrl_c() { | |
echo "Cleaning up..." | |
pid=$(cat pidfile) | |
rm -f $p;rm cmds;rm pidfile;kill $pid 2>/dev/null | |
if [[ "$?" -eq "0" ]]; | |
then | |
echo "Exit success";exit 0 | |
else | |
exit 1 | |
fi | |
} | |
listen(){ | |
([ ! -p "$p" ]) && mkfifo $p | |
(mosquitto_sub -h $host -u $user -P $password -p $port -t $topic >$p) & | |
echo "$!" > pidfile | |
while read line <$p | |
do | |
echo $line > cmds | |
if grep -q "toggle" cmds; then | |
gpioctl dirout-high 0 > /dev/null && sleep 1 && gpioctl dirout-low 0 > /dev/null | |
fi | |
done | |
} | |
trap ctrl_c INT | |
listen |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment