mirror of
https://github.com/binary-kitchen/doorlockd
synced 2024-12-22 10:24:26 +01:00
Ralf Ramsauer
b9a1bfc566
Assisted by nice gpio-wait helper. Signed-off-by: Ralf Ramsauer <ralf@binary-kitchen.de>
24 lines
332 B
Bash
Executable File
24 lines
332 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 22
|
|
ret=$?
|
|
|
|
if [ $ret -eq 0 ]; then
|
|
publish "closed"
|
|
elif [ $ret -eq 1 ]; then
|
|
publish "open"
|
|
fi
|
|
done
|