Skip to content

Instantly share code, notes, and snippets.

@hallgren
Last active June 28, 2017 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hallgren/8cec28707047ec0a20750bdc3aaf1661 to your computer and use it in GitHub Desktop.
Save hallgren/8cec28707047ec0a20750bdc3aaf1661 to your computer and use it in GitHub Desktop.
#!/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