add buttons to webinterface to control the projector and screen

correct the max calculation in peoplecounter
master
Level2 Pidor 2016-02-04 23:50:29 +01:00
parent c7cd9394f4
commit 6495f1fbbc
8 changed files with 155 additions and 14 deletions

2
scripts/.gitignore vendored
View File

@ -1 +1,3 @@
spaceapikey.txt
beamerip.txt
peoplecounterip.txt

106
scripts/beamercontrol.sh Executable file
View File

@ -0,0 +1,106 @@
#!/bin/bash
logger $0 1=$1 2=$2
BEAMERIP=$(cat $(dirname "$0")"/beamerip.txt")
function raisescreen() {
echo "Rolling projection screen up"
ssh pi@doorbuzz 'doorbuzz/projectionscreen.sh up'
}
function lowerscreen() {
echo "Rolling projection screen down"
ssh pi@doorbuzz 'doorbuzz/projectionscreen.sh down'
}
function beameroff() {
echo "Switching beamer off"
wget -qO/dev/null http://$projip/tgi/return.tgi?command=2a3102fd0660 #projector off
}
function beameron() {
echo "Switching beamer on"
wget -qO/dev/null http://$projip/tgi/return.tgi?command=2a3101fe0660 #projector on
}
function usage() {
echo "Usage: $0 (beamer|screen) (on|off|down|up)"
exit
}
projip="$(cat $(dirname "$0")"/beamerip.txt")"
case $1 in
beamer)
case $2 in
on) beameron
;;
off) beameroff
;;
*) usage
esac
;;
screen)
case $2 in
down|on) lowerscreen
;;
up|off) raisescreen
;;
*) usage
esac
;;
*)
usage
;;
esac
exit
if [ "$1" = "off" ]
then
(
echo "called with parameter $1"
projip="$BEAMERIP"
if [ "$projip" = "" ]
then
echo "no projector IP found"
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
raisescreen
echo "wget http://$projip/tgi/return.tgi?command=2a3102fd0660 #projector off"
wget -qO - 'http://'"$projip"'/tgi/return.tgi?command=2a3102fd0660' 2>&1
echo $?
else
echo "not disabling projector because source is at $signalsource"
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
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)}')"
if [ "$statusbyte" = "01" ]
then
if [ "$prevstatus" != "on" ]
then
logger -t $(basename $0) "$$ Projector is on"
ssh pi@doorbuzz 'doorbuzz/projectionscreen.sh down'
prevstatus="on"
fi
else
if [ "$prevstatus" != "off" ]
then
logger -t $(basename $0) "$$ Projector is off"
prevstatus="off"
fi
fi
sleep 10
done

View File

@ -1,7 +1,7 @@
#!/bin/bash
if [ "$1" = "" ]
then
echo "usage: $0 {main|chill|status|labsocket|alarm} {on|off}"
echo "usage: $0 {main|chill|status|labsocket|alarm|screen|projector} {on|off}"
exit 1
fi
function dolight() {
@ -27,6 +27,10 @@ function dolight() {
;;
alarm) sudo /root/pidor/rcswitch-pi/send 2 15A 1 "$setvalue"
;;
screen) sudo /root/pidor/scripts/beamercontrol.sh screen "$2"
;;
projector) sudo /root/pidor/scripts/beamercontrol.sh beamer "$2"
;;
esac
# type (2=10bit)
# | house 1-16 (the dial thingie)

View File

@ -66,14 +66,18 @@ do
if [ "$p" != "$oldp" ]
then
logger $(basename $0) changed from $oldp to $p people
if [ "$p" -gt "$oldp" ]
curmax=$(getmaxpeople)
oldmax=$(cat "$MAXFILE")
if [ "$curmax" -gt "$oldmax" ]
then
echo "$p" > "$MAXFILE"
logger $(basename $0) setting max to $curmax because bigger than $oldmax
echo "$curmax" > "$MAXFILE"
fi
fi
oldaverage="$(cat "$PRESENCY")"
newaverage=$(getaveragepeople)
if [ "$oldaverage" -ne "$newaverage" ]
#logger $(basename $0) averages o=$oldaverage n=$newaverage
if [ "$oldaverage" != "$newaverage" ]
then
logger $(basename $0) updated precency average from $oldaverage to $newaverage people
echo "$newaverage" > "$PRESENCY"

View File

@ -0,0 +1 @@
www-data ALL=(root) NOPASSWD: /root/pidor/scripts/beamercontrol.sh

View File

@ -0,0 +1 @@
www-data ALL=(root) NOPASSWD: /root/pidor/rcswitch-pi/send

View File

@ -19,7 +19,10 @@
}
.h1, .h2, .h3, h1, h2, h3 {
margin-top: 10px;
margin-top: 0;
}
.well {
padding: 10px;
}
</style>
@ -37,26 +40,46 @@
</div>
</div>
<div class="row marketing">
<div class="row">
<div class="col-md-6">
<div class=" well">
<h2>Chill</h2>
<p>This enables/disables all the lights of the Chill area</p>
<p><a class="btn btn-success btn-block" data-area="chill" data-status="on" >On</a></p>
<p><a class="btn btn-danger btn-block" data-area="chill" data-status="off" >Off</a></p>
<h1>Chill Switch</h1>
<p><a class="btn btn-success btn-lg btn-block" data-area="chill" data-status="on" >On</a></p>
<p><a class="btn btn-danger btn-lg btn-block" data-area="chill" data-status="off" >Off</a></p>
</div>
</div>
<div class="col-md-6">
<div class=" well">
<h2>Main</h2>
<p>This enables/disables all the lights of Level2</p>
<p><a class="btn btn-success btn-block" data-area="main" data-status="on" >On</a></p>
<p><a class="btn btn-danger btn-block" data-area="main" data-status="off" >Off</a></p>
<h1>Main Switch</h1>
<p><a class="btn btn-success btn-lg btn-block" data-area="main" data-status="on" >On</a></p>
<p><a class="btn btn-danger btn-lg btn-block" data-area="main" data-status="off" >Off</a></p>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class=" well">
<h1>Projection screen</h1>
<p><a class="btn btn-danger btn-lg btn-block" data-area="screen" data-status="off" >^^^ Roll Up ^^^</a></p>
<p><a class="btn btn-success btn-lg btn-block" data-area="screen" data-status="on" >vvv Roll Down vvv</a></p>
Note: switching the projector on will roll the screen down automatically
</div>
</div>
<div class="col-md-6">
<div class=" well">
<h1>Projector</h1>
<p><a class="btn btn-success btn-lg btn-block" data-area="projector" data-status="on" >On</a></p>
<p><a class="btn btn-danger btn-lg btn-block" data-area="projector" data-status="off" >Off</a></p>
</div>
</div>
</div>
</div> <!-- /container -->
<div class="jumbotron hidden-xs">
<script src="jquery.min.js"></script>
<script type="text/javascript">