From 2ff6641898b57351a5d6ac89586a6effd351bf64 Mon Sep 17 00:00:00 2001 From: pidor Date: Thu, 24 Jan 2019 22:42:03 +0100 Subject: [PATCH] remove some logging receiver volume reset semaphore on lightcommander --- scripts/beamercontrol.sh | 27 +++++++++++- scripts/doorbuzz_wrapper.sh | 2 + scripts/lightcommander | 44 +++++++++++++++---- scripts/lockbutton.sh.d/{lights => 01lights} | 0 .../{changestatus => 02changestatus} | 12 +++++ scripts/lockbutton.sh.d/02receiver.sh | 5 --- scripts/lockbutton.sh.d/03receiver.sh | 5 +++ scripts/upd_status.sh | 8 +++- scripts/upd_status.sh.d/lights | 6 ++- 9 files changed, 91 insertions(+), 18 deletions(-) rename scripts/lockbutton.sh.d/{lights => 01lights} (100%) rename scripts/lockbutton.sh.d/{changestatus => 02changestatus} (67%) delete mode 100755 scripts/lockbutton.sh.d/02receiver.sh create mode 100755 scripts/lockbutton.sh.d/03receiver.sh diff --git a/scripts/beamercontrol.sh b/scripts/beamercontrol.sh index 415dcd0..d1de377 100755 --- a/scripts/beamercontrol.sh +++ b/scripts/beamercontrol.sh @@ -118,11 +118,11 @@ function receivercd() { ssh pi@doorbuzz '/usr/bin/irsend SEND_ONCE pioneer "KEY_CD"' } function receivervolumeup() { - echo "Turning reciever volume up" + #echo "Turning reciever volume up" ssh pi@doorbuzz '/usr/bin/irsend SEND_ONCE pioneer "KEY_VOLUMEUP"' } function receivervolumedown() { - echo "Turning reciever volume down" + #echo "Turning reciever volume down" ssh pi@doorbuzz '/usr/bin/irsend SEND_ONCE pioneer "KEY_VOLUMEDOWN"' } function bluray() { @@ -188,6 +188,29 @@ case $1 in ;; off) receiveroff ;; + shutdown) + echo "Receiver shutdown initiated..." + for i in {1..90} + do + if [ "$(cat /run/spacestatus)" = "open" ] + then + echo "space open, stopping receiver shutdown" + exit + fi + receivervolumedown + done + for i in {1..50} + do + if [ "$(cat /run/spacestatus)" = "open" ] + then + echo "space open, stopping receiver shutdown" + exit + fi + receivervolumeup + done + receiveroff + echo "Receiver shutdown finished." + ;; hdmi) receiverhdmi ;; jack1) receiverjack1 diff --git a/scripts/doorbuzz_wrapper.sh b/scripts/doorbuzz_wrapper.sh index 9935d6f..1ada85e 100755 --- a/scripts/doorbuzz_wrapper.sh +++ b/scripts/doorbuzz_wrapper.sh @@ -18,6 +18,8 @@ do logger -t $(basename $0) "phone status change detected" logger -t $(basename $0) "phone ring light on" $(dirname "$0")/lightcommander alarm on >&2 + sleep 20 # make sure it switches off some time + $(dirname "$0")/lightcommander alarm off >&2 #/usr/local/bin/433send 2 15 1 1 >&2 fi diff --git a/scripts/lightcommander b/scripts/lightcommander index 37256bd..0b266f7 100755 --- a/scripts/lightcommander +++ b/scripts/lightcommander @@ -8,6 +8,34 @@ then # echo "usage: $0 {maindoor} {open}" exit 1 fi + + +LockDir="/run/lock/$(basename "$0").run" +P() { + while ! mkdir "$LockDir" 2>/dev/null + do + LockDirStamp=$(stat -c %Y "$LockDir" 2>/dev/null) + if [ "$LockDirStamp" != "" ] && [ "$LockDirStamp" -lt $(date --date "300 seconds ago" +%s) ] + then + rmdir "$LockDir" + logger -t $(basename $0) "$$ deleting stale semaphore dir $LockDir" + fi + sleep 1 + done +} +V() { + rmdir "$LockDir" 2>/dev/null + if [ $? -ne 0 ] + then + logger -t $(basename $0) "$$ semaphore dir $LockDir disappeared while running" + fi +} + +function IRcmd() { + P + sudo /root/pidor/rcswitch-pi/send "$1" "$2" "$3" "$4" + V +} # v---- group A=1, B=2, G=7 # v---- number # /root/pidor/rcswitch-pi/send 2 7 3 1 <-- 0=off 1=on @@ -25,23 +53,23 @@ function dolight() { dolight "3dprinter" $2 dolight "alarm" $2 ;; - main) sudo /root/pidor/rcswitch-pi/send 2 1A 1 "$setvalue" + main) IRcmd 2 1A 1 "$setvalue" if [ "$setvalue" = "0" ] # switch off alarm light when switching off all lights then - sudo /root/pidor/rcswitch-pi/send 2 15A 1 "$setvalue" + IRcmd2 15A 1 "$setvalue" fi ;; - chill) sudo /root/pidor/rcswitch-pi/send 2 1A 2 "$setvalue" + chill) IRcmd 2 1A 2 "$setvalue" ;; - status) sudo /root/pidor/rcswitch-pi/send 2 2A 1 "$setvalue" + status) IRcmd 2 2A 1 "$setvalue" ;; - labsocket) sudo /root/pidor/rcswitch-pi/send 2 15A 6 "$setvalue" + labsocket) IRcmd 2 15A 6 "$setvalue" ;; - alarm) ( sudo /root/pidor/rcswitch-pi/send 2 15A 1 "$setvalue" + alarm) ( IRcmd 2 15A 1 "$setvalue" sleep 1 - sudo /root/pidor/rcswitch-pi/send 2 15A 1 "$setvalue" ) & + IRcmd 2 15A 1 "$setvalue" ) & ;; - 3dprinter) sudo /root/pidor/rcswitch-pi/send 2 7 3 "$setvalue" + 3dprinter) IRcmd 2 7 3 "$setvalue" ;; screen) sudo /root/pidor/scripts/beamercontrol.sh screen "$2" ;; diff --git a/scripts/lockbutton.sh.d/lights b/scripts/lockbutton.sh.d/01lights similarity index 100% rename from scripts/lockbutton.sh.d/lights rename to scripts/lockbutton.sh.d/01lights diff --git a/scripts/lockbutton.sh.d/changestatus b/scripts/lockbutton.sh.d/02changestatus similarity index 67% rename from scripts/lockbutton.sh.d/changestatus rename to scripts/lockbutton.sh.d/02changestatus index b36389f..384bd0d 100755 --- a/scripts/lockbutton.sh.d/changestatus +++ b/scripts/lockbutton.sh.d/02changestatus @@ -1,6 +1,7 @@ #!/bin/bash # changes level2 state by the state of the main door # i.e. people have to leave it open to keep status open +logger -t $(basename $0) "$1 starting" sleep 1 # silly way to debounce if [ ! -f /run/spacestatus ] # needed to init after boot then @@ -9,6 +10,7 @@ fi if [ "$1" = "pushed" ] && [ "$(cat /run/spacestatus)" = "open" ] then + logger -t $(basename $0) "$1 set state to closed" FORM_action="close" /root/pidor/webserver/cgi-bin/pidor.sh /root/pidor/scripts/upd_status.sh fi @@ -16,8 +18,18 @@ if [ "$1" = "released" ] && # if switch was released (the door opened, or [ "$(cat /run/spacestatus)" = "closed" ] # the status was closed # [ $(stat -c "%Y" /run/spacestatus) -lt $(date --date "1 hour ago" +%s) ] # since at least one hour then + logger -t $(basename $0) "$1 waiting 60s" + sleep 60 # wait a bit, to avoid false triggers (wind blowing, people playing with door + nowstate="$(gpio -g read 11)" + if [ "$nowstate" -eq 1 ] + then + logger -t $(basename $0) "$1 Door was closed again ($nowstate) before 60s elapsed, not setting space to open" + exit + fi + logger -t $(basename $0) "$1 set state to open" FORM_action="open" /root/pidor/webserver/cgi-bin/pidor.sh /root/pidor/scripts/upd_status.sh # echo "intrusion detected: space was closed since some time and locked, but now is still closed but unlocked" | wall # logger -t $(basename $0) "INTRUSION ALARM. door was opened while status is closed" fi +logger -t $(basename $0) "$1 done" diff --git a/scripts/lockbutton.sh.d/02receiver.sh b/scripts/lockbutton.sh.d/02receiver.sh deleted file mode 100755 index 3ecb3c1..0000000 --- a/scripts/lockbutton.sh.d/02receiver.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -if [ "$1" = "pushed" ] -then - $(dirname $0)/../lightcommander receiver off -fi diff --git a/scripts/lockbutton.sh.d/03receiver.sh b/scripts/lockbutton.sh.d/03receiver.sh new file mode 100755 index 0000000..a9364d8 --- /dev/null +++ b/scripts/lockbutton.sh.d/03receiver.sh @@ -0,0 +1,5 @@ +#!/bin/bash +if [ "$1" = "pushed" ] +then + $(dirname $0)/../lightcommander receiver shutdown & +fi diff --git a/scripts/upd_status.sh b/scripts/upd_status.sh index d7a5a87..fdf2c38 100755 --- a/scripts/upd_status.sh +++ b/scripts/upd_status.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -x sleep 5 IGNORE_DOORLOCKBUTTON="no" LockDir="/run/$(basename "$0").run" @@ -55,7 +56,10 @@ do if [ -x "$0".d/"$plugin" ] then "$0".d/"$plugin" "$status" "$oldstatus" - logger -t $(basename $0) "$$ called $plugin '$status' '$oldstatus'. ret=$?" + if [ "$status" != "$oldstatus" ] + then + logger -t $(basename $0) "$$ called $plugin '$status' '$oldstatus'. ret=$?" + fi fi done @@ -109,6 +113,6 @@ then fi fi else - rm -f /run/var/netdown.txt # reset + rm -f /run/netdown.txt # reset fi V diff --git a/scripts/upd_status.sh.d/lights b/scripts/upd_status.sh.d/lights index bd2f3a5..12ca5c4 100755 --- a/scripts/upd_status.sh.d/lights +++ b/scripts/upd_status.sh.d/lights @@ -24,7 +24,7 @@ then # switch status lights on, in any case $(dirname "$0")/../lightcommander status on # /usr/local/bin/433send 2 2A 1 1 #on fi -if [ "$1" = "released" ] && # the door has been opened +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 # ( [ "$(date +%s)" -gt $(/root/pidor/scripts/sunset) ] || [ "$(date +%s)" -lt $(/root/pidor/scripts/sunrise) ] ) @@ -35,6 +35,10 @@ then # /usr/local/bin/433send 2 1A 1 1 #on fi +if [ "$1" = "open" ] && [ "$2" = "open" ] +then + $(dirname "$0")/../lightcommander status on +fi # type (2=10bit) # | house 1-16 (the dial thingie) # | |group A-P (the dial thingie)