Last active
June 28, 2017 08:33
-
-
Save hallgren/8cec28707047ec0a20750bdc3aaf1661 to your computer and use it in GitHub Desktop.
This file contains 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=6 | |
ctrl_c() { | |
echo "Cleaning up..." | |
rm cmds_status | |
if [[ "$?" -eq "0" ]]; | |
then | |
echo "Exit success";exit 0 | |
else | |
exit 1 | |
fi | |
} | |
listen(){ | |
while true | |
do | |
OUTPUT="$(/usr/bin/gpioctl get $io_pid)" | |
echo "${OUTPUT}" > cmds_status | |
if grep -q "LOW" cmds_status; then | |
(mosquitto_pub -h $host -u $user -P $password -p $port -t $topic -m "closed") & | |
else | |
(mosquitto_pub -h $host -u $user -P $password -p $port -t $topic -m "open") & | |
fi | |
sleep 2 | |
done | |
} | |
trap ctrl_c INT | |
listen |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment