From 3fabf743f544beaac84f41dcad588ebae5e190f5 Mon Sep 17 00:00:00 2001 From: Level2 DoorBuzz Date: Thu, 24 Mar 2016 23:33:11 +0100 Subject: [PATCH] removed flash by semaphore in redis. error code display on clock dial --- arpspoofdetect.sh | 4 ++-- buzzctrl.sh | 46 +++++++++++++++++++++++++++--------- phone_notification_client.sh | 8 +++---- setneocolor.py | 28 ++++++++++++++++++---- 4 files changed, 64 insertions(+), 22 deletions(-) diff --git a/arpspoofdetect.sh b/arpspoofdetect.sh index f1fa4e6..cfaf413 100755 --- a/arpspoofdetect.sh +++ b/arpspoofdetect.sh @@ -24,7 +24,7 @@ pulseon() { echo $! } -echo "Initializing hardware" +logger $0 "Initializing hardware" # the button ledcolor() { @@ -33,7 +33,7 @@ ledcolor() { blue=$3 showleds set $((red/ATTENUATION)) $((green/ATTENUATION)) $((blue/ATTENUATION)) } -echo "Main loop" +logger $0 "Main loop" while true do if [ $(arp -a | awk '{arp[$2]=$4;ip[$4]=ip[$4]" "$2}END{print ip[arp["(10.2.113.1)"]]}' | wc -w) -gt 1 ] diff --git a/buzzctrl.sh b/buzzctrl.sh index e14e32c..815b7b2 100755 --- a/buzzctrl.sh +++ b/buzzctrl.sh @@ -1,5 +1,4 @@ #!/bin/bash -# led is not neopixel, so use the python lib for that BUTTONPIN=25 BUZZERURL="$(cat "$(dirname "$0")"/secret.txt)/state.xml?relay1State=2&pulseTime1=5" BUZZERSTATUSURL="$(cat "$(dirname "$0")"/secret.txt)/state.xml" @@ -9,11 +8,13 @@ cd $(dirname "$0") showleds() { ./redi.sh </dev/null # sudo python /home/pi/doorbuzz/setneocolor.py $1 $2 $3 $4 @@ -58,7 +59,7 @@ morse[8]="---.." morse[9]="----." morseled() { message=$1 -echo $message + logger $0 morseled $message msglen=${#message} pos=0 morsecode="" @@ -75,14 +76,36 @@ echo $morsecode echo } +dialcode() { +# shows number code on clock dial + message=$1 + logger $0 dialcode $message + msglen=${#message} + pos=0 + while [ $pos -lt $msglen ] + do + dcode="${message:${pos}:1}" + dcode=$((dcode*5)) # convert numbers into clock values + pos=$((pos+1)) +echo $dcode + red=$2 + green=$3 + blue=$4 + showleds set 0 0 0 + showleds number $((red/ATTENUATION)) $((green/ATTENUATION)) $((blue/ATTENUATION)) "$dcode" + sleep 1 + done + showleds set 0 0 0 +} -echo "morsing IP" -morseled "$(hostname -I|awk -F. '{sub(" ","",$NF);printf $NF}')" 255 0 0 -sleep 10 -echo "Main loop" +logger $0 "morsing IP" +#morseled "$(hostname -I|awk -F. '{sub(" ","",$NF);printf $NF}')" 255 0 0 +dialcode "$(hostname -I|awk -F. '{sub(" ","",$NF);printf $NF}')" 255 0 0 +sleep 1 +logger $0 "Main loop" while true do - ledcolor 0 255 255 + #ledcolor 0 255 255 pulsepid=$(pulseon 0 0 255 ) trap "ledcolor 0 0 0;exit" 1 2 3 gpio -g wfi $BUTTONPIN falling @@ -91,12 +114,13 @@ do gpio -g wfi $BUTTONPIN falling done ledcolor 0 255 255 - echo "Pushiii" + logger $0 "Big Red Button pushed" wget -O - -S --timeout=1 --tries=1 "$BUZZERURL" 2>&1 ret=$? if [ $ret -ne 0 ] then - morseled "$ret" 255 0 0 + #morseled "$ret" 255 0 0 + dialcode "$ret" 255 0 0 sleep 5 else while wget -O - --timeout=1 --tries=1 $BUZZERSTATUSURL|grep '1' @@ -107,7 +131,7 @@ do sleep 0.1 done fi - echo "DOOONE" + logger $0 "button push action finished" done diff --git a/phone_notification_client.sh b/phone_notification_client.sh index c69dd5f..984524d 100755 --- a/phone_notification_client.sh +++ b/phone_notification_client.sh @@ -17,10 +17,10 @@ do ret=$? if [ $ret -eq 1 ] # no more coprocess then - echo "connecting to pidor" + logger $0 "connecting to pidor" coproc ssh -i ~/.ssh/doorbuzz $pidor sleep 10 - echo "connected" + logger $0 "connected" echo "flashoff" >&"${COPROC[1]}" ret=0 fi @@ -28,7 +28,7 @@ do then break fi - echo "$status" + logger $0 "$status" done echo "spacestatus" >&"${COPROC[1]}" read status <&"${COPROC[0]}" @@ -46,7 +46,7 @@ do if [ "$new_status" -eq "$old_status" ]; then continue fi - echo "phone status change detected" + logger $0 "phone status change detected" if [ "$new_status" -eq 0 ]; then echo "neoaction=flash" | ./redi.sh echo "flashon" >&"${COPROC[1]}" diff --git a/setneocolor.py b/setneocolor.py index b5e5de2..feb1422 100755 --- a/setneocolor.py +++ b/setneocolor.py @@ -30,6 +30,10 @@ def wheel(pos): def clockcalc(value): return 1+((30+int(value))%60) +def showit(): + if ( valid == "yes" ): + strip.show() + # Main program logic follows: if __name__ == '__main__': # Create NeoPixel object with appropriate configuration. @@ -55,17 +59,31 @@ if __name__ == '__main__': action=myredis.get('neoaction') except: action="set" + try: + valid=myredis.get('valid') + except: + valid="yes" + if ( valid != "yes" ): + continue if(action == "set"): print "Color set to: ",r,g,b for i in range(0,LED_COUNT): strip.setPixelColor(i, Color(r,g,b)) - strip.show() + showit() + if(action == "number"): + tmp=myredis.get('neovalue') + if(not tmp): + continue + i=clockcalc(int(tmp)) + print "Digit ",i," set to: ",r,g,b + strip.setPixelColor(i, Color(r,g,b)) + showit() if(action == "morse"): print "Morsing with: ",r,g,b speed=10 for i in range(0,LED_COUNT): strip.setPixelColor(i, Color(0,0,0)) - morsecode=myredis.get('neomorse') + morsecode=myredis.get('neovalue') morsep=1 for c in morsecode: if c==".": @@ -91,7 +109,7 @@ if __name__ == '__main__': morsep+=1 strip.setPixelColor(morsep, Color(0,0,0)) morsep+=1 - strip.show() + showit() time.sleep(1) if(action == "pulse"): print "Pulsing with: ",r,g,b @@ -112,7 +130,7 @@ if __name__ == '__main__': strip.setPixelColor(clockcalc(j), color) strip.setPixelColor(clockcalc(time.strftime('%M',time.localtime())),Color(30,0,0)) strip.setPixelColor(clockcalc(time.strftime('%S',time.localtime())),Color(0,30,0)) - strip.show() + showit() time.sleep(50/1000.0) if(action == "flash"): @@ -129,7 +147,7 @@ if __name__ == '__main__': for q in range(3): for i in range(0, strip.numPixels(), 3): strip.setPixelColor(i+q, wheel((i+j) % 255)) - strip.show() + showit() time.sleep(wait_ms/1000.0) for i in range(0, strip.numPixels(), 3): strip.setPixelColor(i+q, 0)