From 4dc5da4a2616009330df722a6b0c4e0f893b9659 Mon Sep 17 00:00:00 2001 From: Gunstick Date: Mon, 11 May 2015 00:28:03 +0200 Subject: [PATCH] phone_notification is first method, was later replaces by doorbuzz_wrapper from the doorbuzz project --- scripts/doorbuzz_wrapper.sh | 25 +++++++++++++++++++++++++ scripts/lockbutton.sh.d/lights | 4 ++++ scripts/phone_notification.sh | 33 +++++++++++++++++++++++++++++++++ scripts/upd_status.sh.d/lights | 4 ++++ systemfiles/inittab | 3 ++- 5 files changed, 68 insertions(+), 1 deletion(-) create mode 100755 scripts/doorbuzz_wrapper.sh create mode 100755 scripts/phone_notification.sh diff --git a/scripts/doorbuzz_wrapper.sh b/scripts/doorbuzz_wrapper.sh new file mode 100755 index 0000000..b8f2ad3 --- /dev/null +++ b/scripts/doorbuzz_wrapper.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# put into /root/.ssh/authorized_keys this: +# command="/root/pidor/scripts/doorbuzz_wrapper.sh" ssh-rsa AAAAB3.......................7fEbKbG2UcaO4d0YZ67T pi@doorbuzz + +while read cmd +do + if [ "$cmd" = "spacestatus" ] + then + cat /var/run/spacestatus + fi + + if [ "$cmd" = "flashon" ] + then + logger -t $(basename $0) "phone status change detected" + logger -t $(basename $0) "phone ring light on" + /usr/local/bin/433send 2 15 1 1 >&2 + fi + + if [ "$cmd" = "flashoff" ] + then + logger -t $(basename $0) "phone status change detected" + logger -t $(basename $0) "phone ring light off" + /usr/local/bin/433send 2 15 1 0 >&2 + fi +done diff --git a/scripts/lockbutton.sh.d/lights b/scripts/lockbutton.sh.d/lights index d583849..f6ba977 100755 --- a/scripts/lockbutton.sh.d/lights +++ b/scripts/lockbutton.sh.d/lights @@ -15,6 +15,10 @@ then done logger -t $(basename $0) "all lights should be off now" fi +if [ "$1" = "released" ] +then # switch status lights on, in any case + /usr/local/bin/433send 2 1A 2 1 #on +fi if [ "$1" = "released" ] && # the door has been opened # [ "$(cat /run/spacestatus)" = "open" ] && # status is open # [ "$(stat -c %Y /run/spacestatus)" -gt "$(date --date "50 minutes ago" +%s)" ] && # since less than 5 minutes diff --git a/scripts/phone_notification.sh b/scripts/phone_notification.sh new file mode 100755 index 0000000..e43b868 --- /dev/null +++ b/scripts/phone_notification.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +url=http://10.2.113.137 +run_file="/var/run/phone_ringing_status" + +while true +do + sleep 1 + if ! [ "$(cat /var/run/spacestatus)" = "open" ]; then + continue + else + if ! [ -e "$run_file" ]; then + touch $run_file + fi + + curl -q "$url" 2>/dev/null | grep Ringing + new_status=$? + old_status=$(cat ${run_file}) + + if [ "$new_status" -eq "$old_status" ]; then + continue + fi + logger -t $(basename $0) "phone status change detected" + if [ "$new_status" -eq 0 ]; then + logger -t $(basename $0) "phone ring light on" + /usr/local/bin/433send 2 15 1 1 + else + logger -t $(basename $0) "phone ring light off" + /usr/local/bin/433send 2 15 1 0 + fi + echo $new_status > ${run_file} + fi +done diff --git a/scripts/upd_status.sh.d/lights b/scripts/upd_status.sh.d/lights index d583849..f6ba977 100755 --- a/scripts/upd_status.sh.d/lights +++ b/scripts/upd_status.sh.d/lights @@ -15,6 +15,10 @@ then done logger -t $(basename $0) "all lights should be off now" fi +if [ "$1" = "released" ] +then # switch status lights on, in any case + /usr/local/bin/433send 2 1A 2 1 #on +fi if [ "$1" = "released" ] && # the door has been opened # [ "$(cat /run/spacestatus)" = "open" ] && # status is open # [ "$(stat -c %Y /run/spacestatus)" -gt "$(date --date "50 minutes ago" +%s)" ] && # since less than 5 minutes diff --git a/systemfiles/inittab b/systemfiles/inittab index 0854555..1e41501 100644 --- a/systemfiles/inittab +++ b/systemfiles/inittab @@ -72,4 +72,5 @@ po::powerokwait:/etc/init.d/powerfail stop T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100 # pidor -P0:2345:respawn:/root/lockbutton.sh +P0:2345:respawn:/root/pidor/scripts/lockbutton.sh +#P1:2345:respawn:/root/pidor/scripts/phone_notification.sh