On RPI we use a simple python script that is run at system startup. DEATHFISH 2 uses 3 screens that share data with Multicasting. Thus, we can use this script to launch RealDash immediately when Multicasting address can be connected to (the screen with Multicasting host has started). Multicasting host will also send a shutdown command to all others in Multicasting network.
Script requires two parameters, ip address and port of the RD Multicasting host. It puts RPI CPU governor into power save mode and disables the HDMI output when RealDash is not running and just attempts to connect to Multicast host. If connection is successful, CPU is set to performance mode, HDMI is enabled and RealDash is launched.
Hope this is helpful, if you don’t use Multicasting, maybe you can rip out the interesting parts from this script.
import socket
from time import sleep
import subprocess
import psutil
import sys
HOST = sys.argv[1] #'172.17.0.1'
PORT = int(sys.argv[2]) #6558
def connect(host, port):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ip = socket.gethostbyname(HOST)
s.connect((ip, PORT))
return s
except Exception as e:
print(e)
return None
def enable_hdmi(enable):
try:
if enable:
subprocess.call(["xset", "dpms", "force", "on"])
subprocess.call(["xset", "dpms", "0", "0", "0"])
else:
subprocess.call(["xset", "dpms", "force", "off"])
subprocess.call(["xset", "dpms", "0", "0", "60"])
except:
print('no xset')
def enable_powersave(enable):
try:
if enable:
subprocess.call(["sudo", "cpufreq-set", "-g", "powersave"])
else:
subprocess.call(["sudo", "cpufreq-set", "-g", "performance"])
except:
print('no cpufreq-set')
def is_running(processName):
for proc in psutil.process_iter():
#print(proc.name)
try:
if processName.lower() in proc.name().lower() and proc.status() != 'zombie':
return True
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
return False
try:
while True:
if not is_running('realdash'):
enable_hdmi(False)
enable_powersave(True)
s = connect(HOST, PORT)
if s != None:
print('Multicasting is online at', HOST, PORT)
s.shutdown(2)
s.close()
enable_powersave(False)
enable_hdmi(True)
print('Launching RealDash')
subprocess.Popen(['realdash'])
sleep(30)
else:
print('Multicasting is offline at', HOST, PORT)
sleep(1.0)
else:
sleep(1.0)
except:
print("out")
enable_hdmi(True)