From ed85f9a89f056b85fcb3aea0ed8b97ebff8eccce Mon Sep 17 00:00:00 2001 From: Level2 DoorBuzz Date: Mon, 25 Jan 2016 23:30:15 +0100 Subject: [PATCH] prepare to show live people counter value --- README.txt | 3 ++- arpspoofdetect.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ peoplecounter.sh | 5 +++++ presency.py | 8 ++++++++ videoplayer.sh | 1 + 5 files changed, 63 insertions(+), 1 deletion(-) create mode 100755 arpspoofdetect.sh create mode 100755 peoplecounter.sh create mode 100644 presency.py diff --git a/README.txt b/README.txt index 8176f0b..eb221a2 100644 --- a/README.txt +++ b/README.txt @@ -13,7 +13,7 @@ how to install sudo vi /etc/xdg/lxsession/LXDE/autostart remove screensaver -sudo apt-get install unclutter xdotool git-core screen imagemagick +sudo apt-get install unclutter xdotool git-core screen imagemagick x11-xserver-utils git clone git://git.drogon.net/wiringPi cd wiringPi ./build @@ -27,6 +27,7 @@ cat > /home/pi/.config/lxsession/LXDE/autostart <<"EOF" @sudo python ./doorbuzz/setneocolor.py @./doorbuzz/buzzctrl.sh @./doorbuzz/videoplayer.sh +@./doorbuzz/arpspoofdetect.sh @sudo python ./doorbuzz/shutdownbutton.py @./doorbuzz/phone_notification_client.sh EOF diff --git a/arpspoofdetect.sh b/arpspoofdetect.sh new file mode 100755 index 0000000..f1fa4e6 --- /dev/null +++ b/arpspoofdetect.sh @@ -0,0 +1,47 @@ +#!/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" +ATTENUATION=4 +# file secret.txt should contain username:password +cd $(dirname "$0") + +showleds() { + ./redi.sh </dev/null 2>&1 & + echo $! +} + +echo "Initializing hardware" +# the button + +ledcolor() { + red=$1 + green=$2 + blue=$3 + showleds set $((red/ATTENUATION)) $((green/ATTENUATION)) $((blue/ATTENUATION)) +} +echo "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 ] +then + ledcolor 255 50 50 + sleep 1 + pulseon 255 255 255 + sleep 60 +fi +done + diff --git a/peoplecounter.sh b/peoplecounter.sh new file mode 100755 index 0000000..1f38067 --- /dev/null +++ b/peoplecounter.sh @@ -0,0 +1,5 @@ +#!/bin/bash +wget -qO - http://10.2.113.6/output.cgi | +sed 's/.*Occupancy://'| +awk '{print $2}' + diff --git a/presency.py b/presency.py new file mode 100644 index 0000000..8d486b6 --- /dev/null +++ b/presency.py @@ -0,0 +1,8 @@ +# this gives number of people present via spaceapi +# but if network down, this does not work +# better get data direct from pidor or peoplecounter +import urllib, json +url = "https://spaceapi.syn2cat.lu/status/json" +response = urllib.urlopen(url); +data = json.loads(response.read()) +print data["sensors"]["people_now_present"][0]["value"] diff --git a/videoplayer.sh b/videoplayer.sh index 33f9f56..4406d3e 100755 --- a/videoplayer.sh +++ b/videoplayer.sh @@ -7,6 +7,7 @@ fi killall feh trap "killall feh; killall omxplayer" 1 2 3 15 feh -F -x black.png & +#feh black.png & while true do if [ "$(python ./spacestatus.py)" = "False" ]