detect if chromecast is idle and shotdown beamer on space close

beamer IP address out of script
master
Level2 Pidor 2016-11-17 19:27:24 +01:00
parent 14d6ef789a
commit b02efa5861
6 changed files with 49 additions and 6 deletions

View File

@ -9,6 +9,7 @@ P0:2345:respawn:/root/pidor/scripts/lockbutton.sh
P1:2345:respawn:/root/pidor/scripts/beamerdetect.sh P1:2345:respawn:/root/pidor/scripts/beamerdetect.sh
P2:2345:respawn:/root/pidor/scripts/ws4beamer_status.py P2:2345:respawn:/root/pidor/scripts/ws4beamer_status.py
P3:2345:respawn:/root/pidor/scripts/peoplecounter-realtime.sh P3:2345:respawn:/root/pidor/scripts/peoplecounter-realtime.sh
P4:2345:respawn:/root/pidor/scripts/caststatus.py
put the beamer IP into beamerip.txt put the beamer IP into beamerip.txt
put the peoplecounter ip into peoplecounterip.txt put the peoplecounter ip into peoplecounterip.txt
@ -20,4 +21,11 @@ fill in the crontab
needs an apache, for some silly historic reason, and for the lights commander needs an apache, for some silly historic reason, and for the lights commander
cd ~/pidor/www && ./intallwebsite.sh cd ~/pidor/www && ./intallwebsite.sh
If you have a chromecast, script to switch off if chromecast is iddle:
cd ~/pidor
git clone git@github.com:balloob/pychromecast.git
cd pychromecast
sudo apt-get install python-dev python-pip
sudo pip install --upgrade pip
sudo pip install -r requirements.txt

View File

@ -27,8 +27,12 @@ then
fi fi
signalsource="$(wget -qO - 'http://'"$projip"'/tgi/return.tgi?query=info' |awk -F'[<>]' '/<info>/{print substr($3,33,2)}')" signalsource="$(wget -qO - 'http://'"$projip"'/tgi/return.tgi?query=info' |awk -F'[<>]' '/<info>/{print substr($3,33,2)}')"
#if [ "$signalsource" = "00" ] || [ "$signalsource" = "15" ] || [ "$signalsource" = "" ] #if [ "$signalsource" = "00" ] || [ "$signalsource" = "15" ] || [ "$signalsource" = "" ]
if [ "$signalsource" = "00" ] || [ "$signalsource" = "02" ] || [ "$signalsource" = "" ] if [ "$signalsource" = "00" ] ||
then [ "$signalsource" = "02" ] ||
[ "$signalsource" = "" ] ||
( [ "$signalsource" = "15" ] &&
[ "$(cat /var/run/caststatus)" = "Backdrop" ] )
then # port 15 is hdmi1 (chromecast)
raisescreen raisescreen
echo "wget http://$projip/tgi/return.tgi?command=2a3102fd0660 #projector off" echo "wget http://$projip/tgi/return.tgi?command=2a3102fd0660 #projector off"
wget -qO - 'http://'"$projip"'/tgi/return.tgi?command=2a3102fd0660' 2>&1 wget -qO - 'http://'"$projip"'/tgi/return.tgi?command=2a3102fd0660' 2>&1

26
scripts/caststatus.py Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env python2.7
from __future__ import print_function
import time,sys,os
sys.path.append(os.path.dirname(__file__) + "/../pychromecast/")
import pychromecast
#mycastname=pychromecast.get_chromecasts_as_dict().keys()[0]
mycastname="Level2 Chillcast DVI1"
cast = pychromecast.get_chromecast(friendly_name=mycastname)
cast.wait()
print(cast.device.friendly_name)
offlinetime=0
while True:
caststatus=cast.status.display_name
print(caststatus)
text_file = open("/var/run/caststatus", "w")
text_file.write("%s" % caststatus)
text_file.close()
if(caststatus == "Backdrop"):
offlinetime+=1
else:
offlinetime=0
if(offlinetime>10):
#print("Chromecast not streaming, switching to slideshow")
offlinetime=0
time.sleep(10)
cast.quit_app()

View File

@ -1,8 +1,9 @@
#!/bin/bash #!/bin/bash
url=http://10.2.113.137 url=http://$(cat $(dirname "$0")"/phoneip.txt")
run_file="/var/run/phone_ringing_status" run_file="/var/run/phone_ringing_status"
new_status=0
old_status=0
while true while true
do do
sleep 1 sleep 1

View File

@ -2,13 +2,17 @@
import requests import requests
import flask import flask
import re import re
import os
with open( os.path.dirname(os.path.realpath(__file__)) + "/beamerip.txt", 'r') as f:
beamerip = f.readline()
app = flask.Flask(__name__) app = flask.Flask(__name__)
@app.route("/") @app.route("/")
def status(): def status():
try: try:
res = requests.get("http://10.2.113.7/tgi/return.tgi?query=info", timeout=1) res = requests.get("http://"+beamerip+"/tgi/return.tgi?query=info", timeout=1)
if "NG" in res.content: if "NG" in res.content:
return "0" return "0"
reg_res = re.findall(b"<info>([^<]*)</info>", res.content) reg_res = re.findall(b"<info>([^<]*)</info>", res.content)

View File

@ -76,4 +76,4 @@ P0:2345:respawn:/root/pidor/scripts/lockbutton.sh
P1:2345:respawn:/root/pidor/scripts/beamerdetect.sh P1:2345:respawn:/root/pidor/scripts/beamerdetect.sh
P2:2345:respawn:/root/pidor/scripts/ws4beamer_status.py P2:2345:respawn:/root/pidor/scripts/ws4beamer_status.py
P3:2345:respawn:/root/pidor/scripts/peoplecounter-realtime.sh P3:2345:respawn:/root/pidor/scripts/peoplecounter-realtime.sh
P4:2345:respawn:/root/pidor/scripts/caststatus.py