1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-12-22 18:34:25 +01:00
doorlockd-mirror/doorstate
Ralf Ramsauer 6fc923a371 doorstate: Use variable instead of constant value
Signed-off-by: Ralf Ramsauer <ralf@binary-kitchen.de>
2019-06-15 22:42:01 +02:00

24 lines
335 B
Bash
Executable File

#!/bin/bash
GPIO=22
function publish {
mosquitto_pub -r -t kitchen/doorlock/frontdoor/doorstate -m "$1"
}
if [ "$(id -u)" != "0" ]; then
echo "Please run as root!"
exit -1
fi
while true; do
gpio-wait /dev/gpiochip0 $GPIO
ret=$?
if [ $ret -eq 0 ]; then
publish "closed"
elif [ $ret -eq 1 ]; then
publish "open"
fi
done