parent
							
								
									210d979eef
								
							
						
					
					
						commit
						3e7027dd82
					
				| 
						 | 
				
			
			@ -0,0 +1,23 @@
 | 
			
		|||
Pidor is controlling the state of Level2 on the website, spaceapi and twitter
 | 
			
		||||
 | 
			
		||||
This documentation is work in progress, sorry about that.
 | 
			
		||||
 | 
			
		||||
Install
 | 
			
		||||
put this in /etc/inittab (see example in systemfiles/inittab)
 | 
			
		||||
# pidor
 | 
			
		||||
P0:2345:respawn:/root/pidor/scripts/lockbutton.sh
 | 
			
		||||
P1:2345:respawn:/root/pidor/scripts/beamerdetect.sh
 | 
			
		||||
P2:2345:respawn:/root/pidor/scripts/ws4beamer_status.py
 | 
			
		||||
P3:2345:respawn:/root/pidor/scripts/peoplecounter-realtime.sh
 | 
			
		||||
 | 
			
		||||
put the beamer IP into beamerip.txt
 | 
			
		||||
put the peoplecounter ip into peoplecounterip.txt
 | 
			
		||||
 | 
			
		||||
fill in the crontab
 | 
			
		||||
* * * * * /root/pidor/scripts/dhcp2presency.sh
 | 
			
		||||
* * * * * /root/pidor/scripts/upd_status.sh > /run/spacestatus.out 2>&1
 | 
			
		||||
 | 
			
		||||
needs an apache, for some silly historic reason, and for the lights commander
 | 
			
		||||
cd ~/pidor/www && ./intallwebsite.sh
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1,19 +1,34 @@
 | 
			
		|||
#!/bin/bash
 | 
			
		||||
BEAMERIP=$(cat $(dirname "$0")"/beamerip.txt")
 | 
			
		||||
function raisescreen() {
 | 
			
		||||
  echo "Rolling projection screen up"
 | 
			
		||||
  ssh pi@doorbuzz 'doorbuzz/projectionscreen.sh up'
 | 
			
		||||
}
 | 
			
		||||
function pingall() {
 | 
			
		||||
  i=1
 | 
			
		||||
  while [ $i -lt 255 ]
 | 
			
		||||
  do
 | 
			
		||||
    ping -c 1 10.2.113.$i -q >/dev/null &
 | 
			
		||||
    i=$((i+1))
 | 
			
		||||
  done
 | 
			
		||||
  wait 
 | 
			
		||||
}
 | 
			
		||||
if [ "$1" = "off" ]
 | 
			
		||||
then
 | 
			
		||||
  (
 | 
			
		||||
  echo "called with parameter $1"
 | 
			
		||||
  projip=$(arp -an|awk -F'[()]' '/00:50:41:79:d1:34/{print $2}')
 | 
			
		||||
  projip="$BEAMERIP"
 | 
			
		||||
  if [ "$projip" = "" ]
 | 
			
		||||
  then
 | 
			
		||||
    echo "no projector IP found"
 | 
			
		||||
    arp -a
 | 
			
		||||
    arp -a 
 | 
			
		||||
    raisescreen
 | 
			
		||||
    exit
 | 
			
		||||
  fi
 | 
			
		||||
  signalsource="$(wget -qO - 'http://'"$projip"'/tgi/return.tgi?query=info' |awk -F'[<>]' '/<info>/{print substr($3,33,2)}')"
 | 
			
		||||
  if [ "$signalsource" = "00" ] || [ "$signalsource" = "15" ] || [ "$signalsource" = "" ]
 | 
			
		||||
  then
 | 
			
		||||
    ssh pi@doorbuzz 'doorbuzz/projectionscreen.sh up'
 | 
			
		||||
    raisescreen
 | 
			
		||||
    echo "wget http://$projip/tgi/return.tgi?command=2a3102fd0660 #projector off"
 | 
			
		||||
    wget -qO - 'http://'"$projip"'/tgi/return.tgi?command=2a3102fd0660' 2>&1 
 | 
			
		||||
    echo $? 
 | 
			
		||||
| 
						 | 
				
			
			@ -22,12 +37,20 @@ then
 | 
			
		|||
  fi
 | 
			
		||||
  ) | logger -t "$(basename $0) $$"
 | 
			
		||||
  exit
 | 
			
		||||
fi &
 | 
			
		||||
if [ "$1" = "off" ]
 | 
			
		||||
then
 | 
			
		||||
  exit # because the if before is in background 
 | 
			
		||||
fi
 | 
			
		||||
prevstatus="unknown"
 | 
			
		||||
while true
 | 
			
		||||
do
 | 
			
		||||
  projip=$(arp -an|awk -F'[()]' '/00:50:41:79:d1:34/{print $2}')
 | 
			
		||||
  # from the acer webpage we read that bytes 30-31 contain 00 if poer off and 01 if power on
 | 
			
		||||
  if [ $(date +%H) -eq 23 ]
 | 
			
		||||
  then
 | 
			
		||||
    pingall
 | 
			
		||||
  fi
 | 
			
		||||
  projip="$BEAMERIP"
 | 
			
		||||
  # from the acer webpage we read that bytes 30-31 contain 00 if power off and 01 if power on
 | 
			
		||||
  # we only test if 01, because if off, it can also give no response
 | 
			
		||||
  # but seems to be bytes 32-33 more accurate
 | 
			
		||||
  statusbyte="$(wget -qO - 'http://'"$projip"'/tgi/return.tgi?query=info'|awk -F'[<>]' '/<info>/{print substr($3,31,2)}')"  
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,16 @@
 | 
			
		|||
#!/bin/bash
 | 
			
		||||
PEOPLECOUNTERIP=$(cat $(dirname "$0")"/peoplecounterip.txt")
 | 
			
		||||
# we now have a people counter
 | 
			
		||||
p="$(
 | 
			
		||||
 wget -qO - "http://$PEOPLECOUNTERIP/output.cgi?t=$(date +%s)" |
 | 
			
		||||
 sed 's/.*Occupancy://'|
 | 
			
		||||
 awk '{print $2}')"
 | 
			
		||||
if [ "$p" != "" ]
 | 
			
		||||
then
 | 
			
		||||
  echo "$p" > /run/presency
 | 
			
		||||
else
 | 
			
		||||
  logger $0 cannot access people counter. fallback to dhcp value guessing
 | 
			
		||||
fi
 | 
			
		||||
n=0
 | 
			
		||||
for i in $(ls /run/dhcp-leases/)
 | 
			
		||||
do
 | 
			
		||||
| 
						 | 
				
			
			@ -18,4 +30,7 @@ do
 | 
			
		|||
    fi
 | 
			
		||||
  fi
 | 
			
		||||
done
 | 
			
		||||
echo "$n" > /run/presency
 | 
			
		||||
if [ "$p" = "" ]  # write DHCP count if people counter offline
 | 
			
		||||
then
 | 
			
		||||
  echo "$n" > /run/presency
 | 
			
		||||
fi
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,6 +2,10 @@
 | 
			
		|||
# changes level2 state by the state of the main door
 | 
			
		||||
# i.e. people have to leave it open to keep status open
 | 
			
		||||
sleep 1   # silly way to debounce 
 | 
			
		||||
if [ ! -f /run/spacestatus ]  # needed to init after boot
 | 
			
		||||
then
 | 
			
		||||
  cp -p /root/var/spacestatus /run/spacestatus
 | 
			
		||||
fi
 | 
			
		||||
if [ "$1" = "pushed" ] && 
 | 
			
		||||
   [ "$(cat /run/spacestatus)" = "open" ]   
 | 
			
		||||
then
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,34 @@
 | 
			
		|||
#!/bin/bash
 | 
			
		||||
#update peoplecounter number in realtime
 | 
			
		||||
#but: this is too intrusive. should only update when the count of 
 | 
			
		||||
@ people has not changed for a certain time
 | 
			
		||||
PEOPLECOUNTERIP=$(cat $(dirname "$0")"/peoplecounterip.txt")
 | 
			
		||||
state="online"
 | 
			
		||||
while true
 | 
			
		||||
do
 | 
			
		||||
  p="$(
 | 
			
		||||
    wget -qO - "http://$PEOPLECOUNTERIP/output.cgi?t=$(date +%s)" |
 | 
			
		||||
    sed 's/.*Occupancy://'|
 | 
			
		||||
    awk '{print $2}')"
 | 
			
		||||
  if [ "$p" != "" ]
 | 
			
		||||
  then
 | 
			
		||||
    oldp="$(cat /run/peoplecounter)"
 | 
			
		||||
    echo "$p" > /run/peoplecounter
 | 
			
		||||
    if [ "$p" != "$oldp" ]
 | 
			
		||||
    then
 | 
			
		||||
      logger $0 changed from $oldp to $p people
 | 
			
		||||
    fi
 | 
			
		||||
    if [ "$state" = "offline" ]
 | 
			
		||||
    then
 | 
			
		||||
      state="online"
 | 
			
		||||
      logger $0 people counter online
 | 
			
		||||
    fi
 | 
			
		||||
  else
 | 
			
		||||
    if [ "$state" = "online" ]
 | 
			
		||||
    then
 | 
			
		||||
      state="offline"
 | 
			
		||||
      logger $0 people counter offline
 | 
			
		||||
    fi
 | 
			
		||||
  fi
 | 
			
		||||
  sleep 10
 | 
			
		||||
done
 | 
			
		||||
| 
						 | 
				
			
			@ -1,4 +1,5 @@
 | 
			
		|||
#!/bin/bash
 | 
			
		||||
sleep 5
 | 
			
		||||
IGNORE_DOORLOCKBUTTON="no"
 | 
			
		||||
LockDir="/run/$(basename "$0").run"
 | 
			
		||||
spaceapikey="$(cat "$(dirname $0)"/spaceapikey.txt)"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,15 @@
 | 
			
		|||
#!/bin/bash
 | 
			
		||||
# this script only makes sense if there is a good people counter installed
 | 
			
		||||
if [ "$1" = "closed" ] && [ "$2" = "open" ]
 | 
			
		||||
then
 | 
			
		||||
  p="$(cat /run/presency)"
 | 
			
		||||
  if [ "$p" != "0" ]
 | 
			
		||||
  then
 | 
			
		||||
    logger $0 There are $p people, closed door from inside waiting 1 min. 
 | 
			
		||||
    sleep 60
 | 
			
		||||
    p="$(cat /run/presency)"
 | 
			
		||||
    logger $0 There are $p people, closed door from inside after 1 min. 
 | 
			
		||||
  else
 | 
			
		||||
    logger $0 There are $p people, correctly closed door from outside. 
 | 
			
		||||
  fi &
 | 
			
		||||
fi
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,23 @@
 | 
			
		|||
#!/usr/bin/env python2.7
 | 
			
		||||
import requests
 | 
			
		||||
import flask
 | 
			
		||||
import re
 | 
			
		||||
 | 
			
		||||
app = flask.Flask(__name__)
 | 
			
		||||
 | 
			
		||||
@app.route("/")
 | 
			
		||||
def status():
 | 
			
		||||
    try:
 | 
			
		||||
      res = requests.get("http://10.2.113.7/tgi/return.tgi?query=info", timeout=1)
 | 
			
		||||
      if "NG" in res.content:
 | 
			
		||||
        return "0"
 | 
			
		||||
      reg_res = re.findall(b"<info>([^<]*)</info>", res.content)
 | 
			
		||||
      status = str(reg_res[0][30:32])
 | 
			
		||||
      if status == "01":
 | 
			
		||||
        return "1"
 | 
			
		||||
    except Exception as e:
 | 
			
		||||
      print(e)
 | 
			
		||||
    return "0"
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    app.run("0.0.0.0", 5042)
 | 
			
		||||
| 
						 | 
				
			
			@ -74,3 +74,6 @@ T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
 | 
			
		|||
# pidor
 | 
			
		||||
P0:2345:respawn:/root/pidor/scripts/lockbutton.sh
 | 
			
		||||
P1:2345:respawn:/root/pidor/scripts/beamerdetect.sh
 | 
			
		||||
P2:2345:respawn:/root/pidor/scripts/ws4beamer_status.py
 | 
			
		||||
P3:2345:respawn:/root/pidor/scripts/peoplecounter-realtime.sh
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue