Improved chromecast handling

added bluray player
master
pidor 2018-01-09 22:08:26 +01:00
parent 32ebc7d2a6
commit e5aeca63cf
7 changed files with 107 additions and 19 deletions

View File

@ -55,8 +55,16 @@ function beameron() {
return 1
}
function dvi() {
echo "Switching to dvi"
wget -qO/dev/null http://$projip/tgi/return.tgi?command=2a3109f6070566 #switch to DVI
currstatus="$(beamerquery)"
if [ "$currstatus" = "02" ] || [ "$currstatus" = "off" ]
then
echo "not switching, already displaying DVI (or off)"
return 1
else
echo "Switching to dvi"
wget -qO/dev/null http://$projip/tgi/return.tgi?command=2a3109f6070566 #switch to DVI
return 0
fi
}
function hdmi1() {
echo "Switching to hdmi1"
@ -116,8 +124,12 @@ function receivervolumedown() {
echo "Turning reciever volume down"
ssh pi@doorbuzz '/usr/bin/irsend SEND_ONCE pioneer "KEY_VOLUMEDOWN"'
}
function bluray() {
echo "Sending bluray player $1"
ssh pi@doorbuzz '/usr/bin/irsend SEND_ONCE SONY_RMT_B104P '"KEY_$(tr [:lower:] [:upper:] <<<$1)"
}
function usage() {
echo "Usage: $0 (beamer|screen|receiver) (on|dvi|hdmi1|hdmi2|vga|off|down|up|vol-|vol+)"
echo "Usage: $0 (beamer|screen|receiver|bluray) (on|dvi|hdmi1|hdmi2|vga|off|down|up|left|right|vol-|vol+|query)"
exit
}
projip="$(cat $(dirname "$0")"/beamerip.txt")"
@ -128,7 +140,11 @@ case $1 in
;;
off) beameroff
;;
dvi) dvi ; beameron && dvi
dvi) dvi && beameron && dvi
;;
dvioff) dvi && beameroff
;;
dvionly) dvi
;;
hdmi1) hdmi1 ; beameron && hdmi1
;;
@ -142,6 +158,8 @@ case $1 in
;;
"vol-") beamervolumedown
;;
"query") beamerquery
;;
*) usage
esac
;;
@ -154,6 +172,15 @@ case $1 in
*) usage
esac
;;
bluray)
case $2 in
down|up|left|right|ok|audio|subtitle|menu|pause|play) bluray $2
;;
on|off) bluray power
;;
*) usage
esac
;;
receiver)
case $2 in
on) receiveron
@ -182,4 +209,4 @@ case $1 in
*)
usage
;;
esac 2>&1 | logger -t $0
esac 2>&1 | tee >(logger -t $0)

View File

@ -30,10 +30,12 @@ then
if [ "$signalsource" = "00" ] ||
[ "$signalsource" = "02" ] ||
[ "$signalsource" = "" ] ||
( [ "$signalsource" = "15" ] &&
[ "$(cat /var/run/caststatus)" = "Backdrop" ] )
[ "$signalsource" = "15" ] # always switch off if on chromecast
# ( [ "$signalsource" = "15" ] &&
# [ "$(cat /var/run/caststatus)" = "Backdrop" ] )
then # port 15 is hdmi1 (chromecast)
raisescreen
lightcommander projector dvioff # swith to slideshow and off
lightcommander projector vol-
echo "wget http://$projip/tgi/return.tgi?command=2a3102fd0660 #projector off"
lightcommander projector off
@ -60,8 +62,8 @@ do
# 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
signalsource="$(wget -qO - 'http://'"$projip"'/tgi/return.tgi?query=info'|awk -F'[<>]' '/<info>/{print substr($3,31,2)}')"
if [ "$signalsource" = "01" ]
projectorstate="$(wget -qO - 'http://'"$projip"'/tgi/return.tgi?query=info'|awk -F'[<>]' '/<info>/{print substr($3,31,2)}')"
if [ "$projectorstate" = "01" ]
then
if [ "$prevstatus" != "on" ]
then
@ -78,13 +80,18 @@ do
fi
# logger -t "$(basename $0) $$" "source=$signalsource cast=$(cat /var/run/caststatus)"
sleep 10
signalsource="$(wget -qO - 'http://'"$projip"'/tgi/return.tgi?query=info' |awk -F'[<>]' '/<info>/{print substr($3,33,2)}')"
caststatus="$(cat /var/run/caststatus)"
# bug: should only consider chromecast if beamer input is chromecast
# logger "ss=$signalsource s=$(cat /root/var/spacestatus) c=$caststatus"
if [ "$caststatus" != "Backdrop" ] && [ "$caststatus" != "None" ] && [ "$caststatus" != "" ] &&
( [ "$signalsource" = "" ] ||
[ "$signalsource" = "00" ] ||
[ "$signalsource" = "02" ] )
[ "$signalsource" = "02" ] ) &&
[ "$(cat /root/var/spacestatus)" = "open" ]
then
logger -t $(basename $0) "$$ signal on chromecast: $caststatus"
logger -t $(basename $0) "$$ switching from $signalsource to hdmi2"
lightcommander projector hdmi2
sleep 3
fi

View File

@ -1,16 +1,27 @@
#!/usr/bin/env python2.7
from __future__ import print_function
import time,sys,os
from subprocess import call
import time,sys,os,syslog
sys.path.append(os.path.dirname(__file__) + "/../pychromecast/")
import pychromecast
import subprocess
#mycastname=pychromecast.get_chromecasts_as_dict().keys()[0]
mycastname="Level2 Chillcast DVI1"
print(mycastname)
syslog.syslog(mycastname)
chromecasts = pychromecast.get_chromecasts()
cast=next(cc for cc in chromecasts if cc.device.friendly_name == mycastname)
cast.wait()
print(cast.device.friendly_name)
offlinetime=0
while True:
oldcaststatus="None"
if(len(sys.argv)>0):
caststatus=cast.status.display_name
print(caststatus)
sys.exit
maxloop=1000
while maxloop:
maxloop=maxloop-1
caststatus=cast.status.display_name
print(caststatus)
text_file = open("/var/run/caststatus", "w")
@ -21,7 +32,15 @@ while True:
else:
offlinetime=0
if(offlinetime>10):
#print("Chromecast not streaming, switching to slideshow")
if(subprocess.check_output(["lightcommander","projector","query"]).rstrip('\n') == "15"):
print("Chromecast not streaming, switching from hdmi2 to slideshow")
syslog.syslog("Chromecast not streaming, switching from hdmi2 to slideshow")
call(["lightcommander","projector","dvionly"])
offlinetime=0
if(oldcaststatus != caststatus):
syslog.syslog("Chromecast changed from "+oldcaststatus+" to "+caststatus)
oldcaststatus=caststatus
time.sleep(10)
cast.quit_app()
print("exiting normally")
syslog.syslog("exiting normally")

View File

@ -2,8 +2,9 @@
if [ "$1" = "" ]
then
echo "usage: $0 {main|chill|status|labsocket|alarm|screen} {on|off}"
echo "usage: $0 {projector} {on|hdmi1|hdmi2|dvi|vga1|off|vol-}"
echo "usage; $0 {receiver} {on|off|hdmi|jack1|jack2|optical|tuner|cd|vol-|vol+}"
echo "usage: $0 projector {on|hdmi1|hdmi2|dvi|vga1|off|vol-|query}"
echo "usage: $0 receiver {on|off|hdmi|jack1|jack2|optical|tuner|cd|vol-|vol+}"
echo "usage: $0 bluray {down|up|left|right|ok|audio|subtitle|menu}"
# echo "usage: $0 {maindoor} {open}"
exit 1
fi
@ -21,6 +22,10 @@ function dolight() {
dolight "alarm" $2
;;
main) sudo /root/pidor/rcswitch-pi/send 2 1A 1 "$setvalue"
if [ "$setvalue" = "0" ] # switch off alarm light when switching off all lights
then
sudo /root/pidor/rcswitch-pi/send 2 15A 1 "$setvalue"
fi
;;
chill) sudo /root/pidor/rcswitch-pi/send 2 1A 2 "$setvalue"
;;
@ -28,7 +33,9 @@ function dolight() {
;;
labsocket) sudo /root/pidor/rcswitch-pi/send 2 15A 6 "$setvalue"
;;
alarm) sudo /root/pidor/rcswitch-pi/send 2 15A 1 "$setvalue"
alarm) ( sudo /root/pidor/rcswitch-pi/send 2 15A 1 "$setvalue"
sleep 1
sudo /root/pidor/rcswitch-pi/send 2 15A 1 "$setvalue" ) &
;;
screen) sudo /root/pidor/scripts/beamercontrol.sh screen "$2"
;;
@ -36,6 +43,8 @@ function dolight() {
;;
receiver) sudo /root/pidor/scripts/beamercontrol.sh receiver "$2"
;;
bluray) sudo /root/pidor/scripts/beamercontrol.sh bluray "$2"
;;
stealth) sudo /root/pidor/scripts/stealth.sh
;;
# maindoor) sudo /root/pidor/scripts/opendoor.sh

View File

@ -90,13 +90,23 @@ do
then
echo "$p" > "$PRESENCYRT"
# echo "p($p) -gt rtoldp($rtoldp)" # debug
aplay '/root/win/Windows XP Logon Sound.wav'
for i in $(seq $((p-rtoldp)))
do
logger "XP logon.wav"
aplay '/root/win/Windows XP Logon Sound.wav' &
sleep 0.2
done &
fi
if [ $p -lt $rtoldp ]
then
echo "$p" > "$PRESENCYRT"
# echo "p($p) -lt rtoldp($rtoldp)" # debug
aplay '/root/win/Windows XP Logoff Sound.wav'
for i in $(seq $((rtoldp-p)))
do
logger "XP logoff.wav"
aplay '/root/win/Windows XP Logoff Sound.wav' &
sleep 0.2
done &
fi
# echo "rtoldp=$p" # debug
rtoldp=$p

View File

@ -19,7 +19,7 @@ then
logger $(basename $0) There are now $np people, after 1 min wait. All OK.
else
logger $(basename $0) There are $np people, after 1 min. Maybe ALARM
python -c 'import smtplib ; server = smtplib.SMTP("mail.syn2cat.lu", 25) ; msg = "Subject: ALARM level2 intruder\n\ndoor closed with people inside" ; server.sendmail("gkess@pt.lu", "gunstick@syn2cat.lu", msg) ; server.quit()'
python -c 'import smtplib ; import sys ; server = smtplib.SMTP("mail.syn2cat.lu", 25) ; msg = "Subject: ALARM level2 intruder\n\ndoor closed with "+sys.argv[1]+" people inside" ; server.sendmail("gkess@pt.lu", "gunstick@syn2cat.lu", msg) ; server.quit()' "$np"
fi
else

View File

@ -95,6 +95,22 @@
<p><a class="btn btn-success btn-lg btn-block" data-area="receiver" data-status="vol-" >Vol-</a></p>
<p><a class="col-md-3 btn btn-danger btn-lg btn-block" data-area="receiver" data-status="off" >Off</a></p>
</div>
</div>
<div class="col-md-6">
<div class=" well">
<h1>Blu Ray</h1>
<p><a class="btn btn-success btn-lg btn-block" data-area="bluray" data-status="on" >On</a></p>
<p><a class="btn btn-success btn-lg btn-block" data-area="bluray" data-status="menu" >Menu</a></p>
<p><a class="btn btn-success btn-lg btn-block" data-area="bluray" data-status="up" >Up</a></p>
<p><a class="btn btn-success btn-lg btn-block" data-area="bluray" data-status="down" >Down</a></p>
<p><a class="btn btn-success btn-lg btn-block" data-area="bluray" data-status="left" >Left</a></p>
<p><a class="btn btn-success btn-lg btn-block" data-area="bluray" data-status="right" >Right</a></p>
<p><a class="btn btn-success btn-lg btn-block" data-area="bluray" data-status="ok" >OK</a></p>
<p><a class="btn btn-success btn-lg btn-block" data-area="bluray" data-status="pause" >Pause</a></p>
<p><a class="btn btn-success btn-lg btn-block" data-area="bluray" data-status="play" >Play</a></p>
<p><a class="btn btn-success btn-lg btn-block" data-area="bluray" data-status="audio" >Language</a></p>
<p><a class="btn btn-success btn-lg btn-block" data-area="bluray" data-status="subtitle" >Subtitle</a></p>
<p><a class="col-md-3 btn btn-danger btn-lg btn-block" data-area="bluray" data-status="off" >Off</a></p>
</div>
</div>
<!--