From e5e3bc99f61f318fbbdfcba4170c63bd5e90588b Mon Sep 17 00:00:00 2001 From: Level2 Pidor Date: Thu, 19 Jan 2017 21:59:15 +0100 Subject: [PATCH] do some sound effects. aplay or speech synth. make peoplecounter play join and leave sounds in timely manner --- scripts/lockbutton.sh.d/01doormessage | 20 ++++++++++++ scripts/lockbutton.sh.d/zzDoormessage | 11 +++++++ scripts/peoplecounter-realtime.sh | 43 ++++++++++++++++++++------ scripts/upd_status.sh | 6 ++-- www/htdocs/lights.level2.lu/index.html | 2 +- 5 files changed, 68 insertions(+), 14 deletions(-) create mode 100755 scripts/lockbutton.sh.d/01doormessage create mode 100755 scripts/lockbutton.sh.d/zzDoormessage diff --git a/scripts/lockbutton.sh.d/01doormessage b/scripts/lockbutton.sh.d/01doormessage new file mode 100755 index 0000000..af72fe4 --- /dev/null +++ b/scripts/lockbutton.sh.d/01doormessage @@ -0,0 +1,20 @@ +#!/bin/bash +( +if [ "$1" = "released" ] +then + sleep 2 + aplay '/root/win/Windows XP Startup.wav' + #espeak -s 130 "Welcome to Level2." 2>/dev/null +fi +if [ "$1" = "pushed" ] +then + aplay '/root/win/Windows XP Critical Error.wav' + sleep 1 + aplay '/root/win/Windows XP Critical Stop.wav' + #espeak -s 130 "Level2 is closing." 2>/dev/null + #espeak -s 120 -p 80 "Please wait, until all lights are off." 2>/dev/null + sleep 1 + #espeak -s 120 -p 80 "I will tell you when I am finished." 2>/dev/null + aplay '/root/win/Windows XP Logoff.wav' +fi +) & diff --git a/scripts/lockbutton.sh.d/zzDoormessage b/scripts/lockbutton.sh.d/zzDoormessage new file mode 100755 index 0000000..820906a --- /dev/null +++ b/scripts/lockbutton.sh.d/zzDoormessage @@ -0,0 +1,11 @@ +#!/bin/bash +if [ "$1" = "released" ] +then + : + # espeak -s 130 "Welcome to Level2." 2>/dev/null +fi +if [ "$1" = "pushed" ] +then + #espeak -s 130 "Thank you for waiting. I am done. Have a nice day." 2>/dev/null + aplay '/root/win/Windows XP Shutdown.wav' +fi diff --git a/scripts/peoplecounter-realtime.sh b/scripts/peoplecounter-realtime.sh index 43238a4..f7c13d9 100755 --- a/scripts/peoplecounter-realtime.sh +++ b/scripts/peoplecounter-realtime.sh @@ -10,7 +10,8 @@ else fi STATSFILE="/run/peoplecounter$DEV" SAMPLES=20 # how many records to keep in file -INTERVAL=10 # how long to wait between polls +INTERVAL=0 # how long to wait between polls +INTERVALSKIP=20 # poll with INTERVAL but only consider every INTERVALSKIP's for SAMPLES MAXFILE="/var/cache/peoplecountermax$DEV" PRESENCY="/run/presency$DEV" # value shown on website # /run/peoplecounter lists all recent reads, newest at end @@ -52,6 +53,7 @@ function addcount() { } PEOPLECOUNTERIP=$(cat $(dirname "$0")"/peoplecounterip.txt") state="online" +rtoldp=0 while true do # scrape new value @@ -59,22 +61,43 @@ do wget -qO - "http://$PEOPLECOUNTERIP/output.cgi?t=$(date +%s)" | sed 's/.*Occupancy://'| awk '{print $2}')" + # echo "p=$p" # debug if [ "$p" != "" ] # oh we got something then oldp="$(getlastpeople)" - addcount "$p" - if [ "$p" != "$oldp" ] + skipcounter=$((skipcounter+1)) + if [ $skipcounter -gt $INTERVALSKIP ] then - logger $(basename $0) changed from $oldp to $p people - curmax=$(getmaxpeople) - oldmax=$(cat "$MAXFILE") - if [ "$curmax" -gt "${oldmax:-0}" ] + # echo "skipcounter expired. updating" # debug + skipcounter=0 + addcount "$p" + # if max then call this: + if [ "$p" != "$oldp" ] then - logger $(basename $0) setting max to $curmax because bigger than ${oldmax:-} - echo "$curmax" > "$MAXFILE" - chmod a+rw "$MAXFILE" + logger $(basename $0) changed from $oldp to $p people + curmax=$(getmaxpeople) + oldmax=$(cat "$MAXFILE") + if [ "$curmax" -gt "${oldmax:-0}" ] + then + logger $(basename $0) setting max to $curmax because bigger than ${oldmax:-} + echo "$curmax" > "$MAXFILE" + chmod a+rw "$MAXFILE" + fi fi fi + if [ $p -gt $rtoldp ] + then + # echo "p($p) -gt rtoldp($rtoldp)" # debug + aplay '/root/win/Windows XP Logon Sound.wav' + fi + if [ $p -lt $rtoldp ] + then + # echo "p($p) -lt rtoldp($rtoldp)" # debug + aplay '/root/win/Windows XP Logoff Sound.wav' + fi + # echo "rtoldp=$p" # debug + rtoldp=$p + oldaverage="$(cat "$PRESENCY")" newaverage=$(getaveragepeople) #logger $(basename $0) averages o=$oldaverage n=$newaverage diff --git a/scripts/upd_status.sh b/scripts/upd_status.sh index e70cae7..d2f089b 100755 --- a/scripts/upd_status.sh +++ b/scripts/upd_status.sh @@ -42,7 +42,7 @@ doorlockbutton="$(cat /run/doorlockbutton)" nai=$(stat -c "%Y" /run/spacestatus) # get mtime as status change time if [ "$status" = "open" ] then - /usr/bin/curl --max-time 1 --silent --insecure --data key="$spaceapikey" --data-urlencode sensors='{"state":{"open":true,"lastchange":'"$nai"'}}' http://spaceapi.syn2cat.lu/sensor/set + /usr/bin/curl --max-time 1 --silent --data key="$spaceapikey" --data-urlencode sensors='{"state":{"open":true,"lastchange":'"$nai"'}}' https://spaceapi.syn2cat.lu/sensor/set #logger -t $(basename $0) "$$ sending status $status to spacapi ret=$?" fi for plugin in $(ls "$0".d) @@ -60,7 +60,7 @@ then # problem: if closing state but not actually shuting door for a longer time, the status in spaceapi # will be the time of closing but not that of actually shutting the door # but the status will only be updated once the door is shut - /usr/bin/curl --max-time 1 --silent --insecure --data key="$spaceapikey" --data-urlencode sensors='{"state":{"open":false,"lastchange":'"$nai"'}}' http://spaceapi.syn2cat.lu/sensor/set + /usr/bin/curl --max-time 1 --silent --data key="$spaceapikey" --data-urlencode sensors='{"state":{"open":false,"lastchange":'"$nai"'}}' https://spaceapi.syn2cat.lu/sensor/set #logger -t $(basename $0) "$$ sending status $status to spacapi ret=$?" fi @@ -74,5 +74,5 @@ if [ "$status" = "closed" ] then presency=0 fi -/usr/bin/curl --max-time 1 --silent --insecure --data key="$spaceapikey" --data-urlencode sensors='{"sensors":{"people_now_present":[{"value":'"$presency"'}]}}' http://spaceapi.syn2cat.lu/sensor/set +/usr/bin/curl --max-time 1 --silent --data key="$spaceapikey" --data-urlencode sensors='{"sensors":{"people_now_present":[{"value":'"$presency"'}]}}' https://spaceapi.syn2cat.lu/sensor/set V diff --git a/www/htdocs/lights.level2.lu/index.html b/www/htdocs/lights.level2.lu/index.html index dcf2553..1ccaab4 100644 --- a/www/htdocs/lights.level2.lu/index.html +++ b/www/htdocs/lights.level2.lu/index.html @@ -91,8 +91,8 @@

Optical (BluRay) 5.1

CD (white laptop)r

Tuner

-

Vol-

Vol+

+

Vol-

Off