missing www
This commit is contained in:
parent
5f7c61f616
commit
cfc7c70d16
131 changed files with 11126 additions and 661 deletions
297
main.py
297
main.py
|
|
@ -23,8 +23,8 @@ Plugins OSC Ports (see LJ.conf)
|
|||
|
||||
'''
|
||||
#import pdb
|
||||
|
||||
from libs3 import log
|
||||
|
||||
print("")
|
||||
print("")
|
||||
log.infog("LJ Laser Server")
|
||||
|
|
@ -52,25 +52,24 @@ settings.Write()
|
|||
from multiprocessing import Process, set_start_method
|
||||
import random, ast
|
||||
from libs3 import plugins
|
||||
|
||||
|
||||
#from libs3 import lasytracer as tracer
|
||||
from libs3 import tracer3 as tracer
|
||||
|
||||
|
||||
#from libs3 import niptracer3 as tracer
|
||||
from libs3 import homographyp, commands, font1
|
||||
#import subprocess
|
||||
import os
|
||||
#import midi
|
||||
#from libs3 import midi3
|
||||
from libs3 import OSC3
|
||||
from websocket_server import WebsocketServer
|
||||
#import socket
|
||||
import types, _thread, time
|
||||
import traceback
|
||||
|
||||
serverIP = gstt.RediServerIP
|
||||
print("Redis server IP :", gstt.RediServerIP)
|
||||
|
||||
|
||||
r = redis.StrictRedis(host=gstt.LjayServerIP , port=6379, db=0)
|
||||
# r = redis.StrictRedis(host=gstt.LjayServerIP , port=6379, db=0, password='-+F816Y+-')
|
||||
r = redis.StrictRedis(host=gstt.RediServerIP , port=6379, db=0)
|
||||
# r = redis.StrictRedis(host=gstt.RediServerIP , port=6379, db=0, password='-+F816Y+-')
|
||||
args =[0,0]
|
||||
|
||||
|
||||
|
|
@ -105,44 +104,20 @@ def dac_process(number, pl):
|
|||
|
||||
|
||||
#
|
||||
# Servers init variables
|
||||
# Init variables
|
||||
#
|
||||
|
||||
print("Start Scene number :",gstt.SceneNumber)
|
||||
|
||||
print("WebUI connect to :", gstt.wwwIP)
|
||||
|
||||
serverIP = gstt.LjayServerIP
|
||||
print("Redis IP :", serverIP)
|
||||
|
||||
oscserverIP = gstt.oscIPin
|
||||
print("OSCserver IP :", oscserverIP)
|
||||
|
||||
nozoscIP = gstt.nozoscip
|
||||
print("Nozosc IP :", nozoscIP)
|
||||
|
||||
debug = gstt.debug
|
||||
print("Debug :", debug)
|
||||
|
||||
|
||||
# Websocket listening port
|
||||
wsPORT = 9001
|
||||
|
||||
# oscserver
|
||||
# OSC Server : accept OSC message on port 8002
|
||||
#oscIPin = "192.168.1.10"s
|
||||
oscserverIPin = serverIP
|
||||
|
||||
print("oscserverIPin", oscserverIPin)
|
||||
oscserverPORTin = 8002
|
||||
|
||||
# OSC Client : to send OSC message to an IP port 8001
|
||||
oscserverIPout = oscserverIP
|
||||
oscserverPORTout = 8001
|
||||
|
||||
|
||||
'''
|
||||
# Nozoid OSC Client : to send OSC message to Nozoid inport 8003
|
||||
|
||||
nozoscIP = gstt.nozoscip
|
||||
print("Nozosc IP :", nozoscIP)
|
||||
NozoscIPout = nozoscIP
|
||||
NozoscPORTout = plugins.Port("nozoid")
|
||||
'''
|
||||
|
|
@ -163,6 +138,18 @@ import socket
|
|||
# OSC
|
||||
#
|
||||
|
||||
# oscserver
|
||||
oscserverIP = gstt.oscIPin
|
||||
|
||||
# OSC Server : accept OSC message on port 8002
|
||||
#oscIPin = "192.168.1.10"s
|
||||
oscserverIPin = serverIP
|
||||
oscserverPORTin = 8002
|
||||
|
||||
# OSC Client : to send OSC message to an IP port 8001
|
||||
oscserverIPout = oscserverIP
|
||||
oscserverPORTout = 8101
|
||||
|
||||
oscserver = OSC3.OSCServer( (oscserverIPin, oscserverPORTin) )
|
||||
oscserver.timeout = 0
|
||||
OSCRunning = True
|
||||
|
|
@ -174,16 +161,27 @@ def handle_timeout(self):
|
|||
oscserver.handle_timeout = types.MethodType(handle_timeout, oscserver)
|
||||
|
||||
|
||||
# OSC default path handler : send incoming OSC message to UI via websocket 9001
|
||||
# OSC default path handler : send incoming OSC message to UIs : OSC 8001 & websocket 9001
|
||||
def handler(path, tags, args, source):
|
||||
|
||||
# OSC ui connection
|
||||
if path == "/connect" :
|
||||
print("OSCUI asked by", source)
|
||||
gstt.TouchOSCUI = True
|
||||
gstt.TouchOSCIP= source[0]
|
||||
print(gstt.LaserNumber)
|
||||
for laserid in range(gstt.LaserNumber):
|
||||
commands.UpdateOSCUI(laserid)
|
||||
return
|
||||
|
||||
oscpath = path.split("/")
|
||||
if gstt.debug > 0:
|
||||
print("")
|
||||
print("OSC handler in main said : path", path," oscpath ", oscpath," args", args)
|
||||
print("OSC handler in main got : path", path," oscpath", oscpath," args", args, " source",source)
|
||||
|
||||
if oscpath[1] != "pong":
|
||||
sendWSall(path + " " + str(args[0]))
|
||||
commands.sendOSCUI(path,oscargs=args)
|
||||
commands.handler(oscpath,args)
|
||||
|
||||
|
||||
|
|
@ -208,83 +206,124 @@ def PingAll():
|
|||
plugins.Ping(plugin)
|
||||
|
||||
|
||||
'''
|
||||
gstt.lasertype[i
|
||||
gstt.sizeX[i] =
|
||||
gstt.sizeY[i] =
|
||||
'''
|
||||
'''
|
||||
# OSC UI feedback
|
||||
def sendOSCUI(oscaddress,oscargs=''):
|
||||
|
||||
if gstt.TouchOSCUI == True:
|
||||
oscmsg = OSC3.OSCMessage()
|
||||
oscmsg.setAddress(oscaddress)
|
||||
oscmsg.append(oscargs)
|
||||
|
||||
oscui = OSC3.OSCClient()
|
||||
oscui.connect((gstt.TouchOSCIP, 8001))
|
||||
print("main sending OSC UI message :", oscmsg, "to", gstt.TouchOSCIP, ":8001")
|
||||
if gstt.debug >0:
|
||||
print("main sending OSC UI message :", oscmsg, "to", gstt.TouchOSCIP, ":8001")
|
||||
|
||||
try:
|
||||
oscui.sendto(oscmsg, (gstt.TouchOSCIP, 8001))
|
||||
oscmsg.clearData()
|
||||
|
||||
except:
|
||||
print ('Connection to OSC UI refused : died ?')
|
||||
pass
|
||||
#time.sleep(0.001
|
||||
'''
|
||||
|
||||
# OSC server Thread : handler, dacs reports and simulator points sender to UI.
|
||||
def osc_thread():
|
||||
|
||||
#while True:
|
||||
try:
|
||||
while True:
|
||||
try:
|
||||
while True:
|
||||
|
||||
time.sleep(0.1)
|
||||
osc_frame()
|
||||
for laserid in range(0,gstt.LaserNumber): # Laser not used -> led is not lit
|
||||
time.sleep(0.1)
|
||||
osc_frame()
|
||||
|
||||
lstate = {'0': 'IDLE', '1': 'PREPARE', '2': "PLAYING", '64': "NOCONNECTION ?" }
|
||||
lstt = r.get('/lstt/'+ str(laserid)).decode('ascii')
|
||||
#print ("laserid", laserid,"lstt",lstt, type(lstt))
|
||||
if gstt.debug >1:
|
||||
print("DAC", laserid, "is in (lstt) :", lstt , lstate[str(lstt)])
|
||||
if lstt == "0": # Dac IDLE state(0) -> led is blue (3)
|
||||
sendWSall("/lstt/" + str(laserid) + " 3")
|
||||
for laserid in range(0,gstt.LaserNumber): # Laser not used -> led is not lit
|
||||
|
||||
if lstt == "1": # Dac PREPARE state (1) -> led is cyan (2)
|
||||
sendWSall("/lstt/" + str(laserid) + " 2")
|
||||
lstate = {'0': 'IDLE', '1': 'PREPARE', '2': "PLAYING", '64': "NOCONNECTION ?" }
|
||||
lstt = r.get('/lstt/'+ str(laserid)).decode('ascii')
|
||||
#print ("laserid", laserid,"lstt",lstt, type(lstt))
|
||||
commands.sendOSCUI("/stt/" + str(laserid), lstate[str(lstt)])
|
||||
if gstt.debug >1:
|
||||
print("DAC", laserid, "is in (lstt) :", lstt , lstate[str(lstt)])
|
||||
if lstt == "0": # Dac IDLE state(0) -> led is blue (3)
|
||||
sendWSall("/lstt/" + str(laserid) + " 3")
|
||||
|
||||
if lstt == "2": # Dac PLAYING (2) -> led is green (1)
|
||||
sendWSall("/lstt/" + str(laserid) + " 1")
|
||||
if lstt == "1": # Dac PREPARE state (1) -> led is cyan (2)
|
||||
sendWSall("/lstt/" + str(laserid) + " 2")
|
||||
|
||||
if lstt == "2": # Dac PLAYING (2) -> led is green (1)
|
||||
sendWSall("/lstt/" + str(laserid) + " 1")
|
||||
|
||||
|
||||
ackstate = {'61': 'ACK', '46': 'FULL', '49': "INVALID", '21': 'STOP', '64': "NOCONNECTION ?", '35': "NOCONNECTION ?" , '97': 'ACK', '70': 'FULL', '73': "INVALID", '33': 'STOP', '100': "NOCONNECTION", '48': "NOCONNECTION", 'a': 'ACK', 'F': 'FULL', 'I': "INVALID", '!': 'STOP', 'd': "NOCONNECTION", '0': "NOCONNECTION"}
|
||||
lack= r.get('/lack/'+str(laserid)).decode('ascii')
|
||||
commands.sendOSCUI("/ack/" + str(laserid), ackstate[str(lack)])
|
||||
if gstt.debug >1:
|
||||
print("DAC", laserid, "answered (lack):", lack, chr(int(lack)), ackstate[str(lack)])
|
||||
|
||||
if chr(int(lack)) == 'a': # Dac sent ACK ("a") -> led is green (1)
|
||||
sendWSall("/lack/" + str(laserid) +" 1")
|
||||
|
||||
if chr(int(lack)) == 'F': # Dac sent FULL ("F") -> led is orange (5)
|
||||
sendWSall("/lack/" + str(laserid) +" 5")
|
||||
|
||||
if chr(int(lack)) == 'I': # Dac sent INVALID ("I") -> led is yellow (4)
|
||||
sendWSall("/lack/" + str(laserid)+" 4")
|
||||
#print lack
|
||||
|
||||
|
||||
ackstate = {'61': 'ACK', '46': 'FULL', '49': "INVALID", '21': 'STOP', '64': "NOCONNECTION ?", '35': "NOCONNECTION ?" , '97': 'ACK', '70': 'FULL', '73': "INVALID", '33': 'STOP', '100': "NOCONNECTION", '48': "NOCONNECTION", 'a': 'ACK', 'F': 'FULL', 'I': "INVALID", '!': 'STOP', 'd': "NOCONNECTION", '0': "NOCONNECTION"}
|
||||
lack= r.get('/lack/'+str(laserid)).decode('ascii')
|
||||
|
||||
if gstt.debug >1:
|
||||
print("DAC", laserid, "answered (lack):", lack, chr(int(lack)), ackstate[str(lack)])
|
||||
|
||||
if chr(int(lack)) == 'a': # Dac sent ACK ("a") -> led is green (1)
|
||||
sendWSall("/lack/" + str(laserid) +" 1")
|
||||
|
||||
if chr(int(lack)) == 'F': # Dac sent FULL ("F") -> led is orange (5)
|
||||
sendWSall("/lack/" + str(laserid) +" 5")
|
||||
|
||||
if chr(int(lack)) == 'I': # Dac sent INVALID ("I") -> led is yellow (4)
|
||||
sendWSall("/lack/" + str(laserid)+" 4")
|
||||
#print lack
|
||||
if lack == "64" or lack =="35": # no connection to dac -> leds are red (6)
|
||||
sendWSall("/lack/" + str(laserid) + " 6")
|
||||
sendWSall("/lstt/" + str(laserid) + " 6")
|
||||
#sendWSall("/lstt/" + str(laserid) + " 0")
|
||||
sendWSall("/points/" + str(laserid) + " 6")
|
||||
|
||||
if lack == "64" or lack =="35": # no connection to dac -> leds are red (6)
|
||||
sendWSall("/lack/" + str(laserid) + " 6")
|
||||
sendWSall("/lstt/" + str(laserid) + " 6")
|
||||
#sendWSall("/lstt/" + str(laserid) + " 0")
|
||||
sendWSall("/points/" + str(laserid) + " 6")
|
||||
|
||||
else:
|
||||
# last number of points sent to etherdream buffer
|
||||
sendWSall("/points/" + str(laserid) + " " + str(r.get('/cap/'+str(laserid)).decode('ascii')))
|
||||
else:
|
||||
# last number of points sent to etherdream buffer
|
||||
sendWSall("/points/" + str(laserid) + " " + str(r.get('/cap/'+str(laserid)).decode('ascii')))
|
||||
|
||||
#print("Sending simu frame from",'/pl/'+str(gstt.SceneNumber)+'/'+str(gstt.Laser))
|
||||
#print(r.get('/pl/'+str(gstt.SceneNumber)+'/'+str(gstt.Laser)))
|
||||
sendWSall("/simul" +" "+ str(r.get('/pl/'+str(gstt.SceneNumber)+'/'+str(gstt.Laser)).decode('ascii')))
|
||||
if random.randint(0,100)>95:
|
||||
plugins.sendbroadcast()
|
||||
#print("Sending simu frame from",'/pl/'+str(gstt.SceneNumber)+'/'+str(gstt.Laser))
|
||||
#print(r.get('/pl/'+str(gstt.SceneNumber)+'/'+str(gstt.Laser)))
|
||||
sendWSall("/simul" +" "+ str(r.get('/pl/'+str(gstt.SceneNumber)+'/'+str(gstt.Laser)).decode('ascii')))
|
||||
#commands.sendOSCUI("/cap/" + str(laserid), str(r.get('/cap/'+str(laserid)).decode('ascii')))
|
||||
if random.randint(0,100)>95:
|
||||
plugins.sendbroadcast()
|
||||
|
||||
|
||||
except Exception as e:
|
||||
import sys, traceback
|
||||
print('\n--------------------------')
|
||||
print('OSC Thread Exception: %s' % e)
|
||||
print('- - - - - - - - - - - - - - ')
|
||||
traceback.print_tb(sys.exc_info()[2])
|
||||
print("\n")
|
||||
except Exception as e:
|
||||
import sys, traceback
|
||||
print('\n--------------------------')
|
||||
print('OSC Thread Exception: %s' % e)
|
||||
print('- - - - - - - - - - - - - - ')
|
||||
traceback.print_tb(sys.exc_info()[2])
|
||||
print("\n")
|
||||
|
||||
#
|
||||
# Websocket part
|
||||
#
|
||||
|
||||
def get_Host_name_IP():
|
||||
try:
|
||||
host_name = socket.gethostname()
|
||||
host_ip = socket.gethostbyname(host_name)
|
||||
print("Hostname : ", host_name)
|
||||
print("IP : ", host_ip)
|
||||
except:
|
||||
print("Unable to get Hostname and IP")
|
||||
return host_ip
|
||||
|
||||
# Called for every WS client connecting (after handshake)
|
||||
def new_client(client, wserver):
|
||||
|
||||
print("New WS client connected and was given id %d" % client['id'])
|
||||
sendWSall("/status Hello " + str(client['id']))
|
||||
#commands.sendOSCUI("/status", "Hello " + str(client['id']))
|
||||
|
||||
for laserid in range(0,gstt.LaserNumber):
|
||||
|
||||
|
|
@ -312,7 +351,13 @@ def new_client(client, wserver):
|
|||
|
||||
# Called for every WS client disconnecting
|
||||
def client_left(client, wserver):
|
||||
print("WS Client(%d) disconnected" % client['id'])
|
||||
|
||||
try:
|
||||
print("WS Client(%d) disconnected" % client['id'])
|
||||
|
||||
except:
|
||||
print("Something weird is coming from",client,"on the wire...")
|
||||
pass
|
||||
|
||||
|
||||
# Called for each WS received message.
|
||||
|
|
@ -334,7 +379,6 @@ def message_received(client, wserver, message):
|
|||
message4plugin = False
|
||||
|
||||
# WS received Message is for a plugin ?
|
||||
|
||||
for plugin in list(gstt.plugins.keys()):
|
||||
|
||||
if oscpath[0].find(plugin) != -1:
|
||||
|
|
@ -346,9 +390,7 @@ def message_received(client, wserver, message):
|
|||
else:
|
||||
print("plugins detected", plugin, "offline.")
|
||||
|
||||
|
||||
# WS received message is an LJ command
|
||||
|
||||
# WS received message is an LJ command
|
||||
if message4plugin == False:
|
||||
|
||||
if len(oscpath) == 1:
|
||||
|
|
@ -374,12 +416,20 @@ def sendWSall(message):
|
|||
#if gstt.debug >0:
|
||||
#print("WS sending %s" % (message))
|
||||
wserver.send_message_to_all(message)
|
||||
|
||||
if gstt.TouchOSCUI == True:
|
||||
if message[:7] == '/status':
|
||||
print("Main WSall", message, message[:6])
|
||||
commands.sendOSCUI('/status', message[8:])
|
||||
if message[:5] == '/line1':
|
||||
print("Main WSall", message, message[:6])
|
||||
commands.sendOSCUI('/line1', message[6:])
|
||||
|
||||
|
||||
'''
|
||||
print ""
|
||||
print "Midi Configuration"
|
||||
midi.InConfig()
|
||||
midi.OutConfig()
|
||||
print ("")
|
||||
log.info("Midi Configuration...")
|
||||
midi3.check()
|
||||
'''
|
||||
|
||||
def fff(name):
|
||||
|
|
@ -395,7 +445,6 @@ def fff(name):
|
|||
print("")
|
||||
log.info("Creating startup point lists...")
|
||||
|
||||
|
||||
if r.set("/clientkey","/pl/"+str(gstt.SceneNumber)+"/")==True:
|
||||
print("sent clientkey : /pl/"+str(gstt.SceneNumber)+"/")
|
||||
|
||||
|
|
@ -436,8 +485,6 @@ if __name__ == '__main__':
|
|||
|
||||
lasernumber = gstt.LaserNumber -1
|
||||
print("LaserNumber = ", gstt.LaserNumber)
|
||||
|
||||
|
||||
log.info("Starting "+str(gstt.LaserNumber) + " DACs process...")
|
||||
|
||||
# Launch one process (a tracer3 instance) by etherdream
|
||||
|
|
@ -471,14 +518,19 @@ if __name__ == '__main__':
|
|||
|
||||
try:
|
||||
|
||||
# Websocket startup
|
||||
wserver = WebsocketServer(wsPORT,host=serverIP)
|
||||
plugins.Init(wserver)
|
||||
|
||||
log.info("Starting servers...")
|
||||
hostIP= get_Host_name_IP()
|
||||
if hostIP != gstt.wwwIP:
|
||||
log.err("Host IP is : "+str(hostIP))
|
||||
log.err("wwwIP in LJ.conf : "+str(gstt.wwwIP))
|
||||
log.err("Update LJ.conf : python3 configure.py")
|
||||
#gstt.wwwIP = hostIP
|
||||
commands.LJautokill()
|
||||
sys.exit()
|
||||
|
||||
# Launch OSC thread listening to oscserver
|
||||
print("Launching OSC server...")
|
||||
print("at", oscserverIPin, "port",str(oscserverPORTin))
|
||||
print("Launching OSC server to receive messages (UI,...)")
|
||||
print("binding at", oscserverIPin, "port",str(oscserverPORTin))
|
||||
oscserver.addMsgHandler( "/noteon", commands.NoteOn)
|
||||
oscserver.addMsgHandler( "/scim", commands.Scim)
|
||||
oscserver.addMsgHandler( "/line1", commands.Line1)
|
||||
|
|
@ -486,19 +538,32 @@ if __name__ == '__main__':
|
|||
# Default OSC handler for all OSC incoming message
|
||||
oscserver.addMsgHandler("default", handler)
|
||||
_thread.start_new_thread(osc_thread, ())
|
||||
|
||||
print("Launching webUI Websocket server...")
|
||||
print("at", serverIP, "port",wsPORT)
|
||||
|
||||
#print()
|
||||
# Websocket listening port
|
||||
print("Listening for WebUI WS...")
|
||||
|
||||
hostIP= get_Host_name_IP()
|
||||
if hostIP != gstt.wwwIP:
|
||||
log.err("wwwIP in config is not set to "+str(hostIP))
|
||||
gstt.wwwIP = hostIP
|
||||
#commands.LJautokill()
|
||||
|
||||
print("binding at", gstt.wwwIP, "port",str(gstt.wsPORT))
|
||||
wserver = WebsocketServer(gstt.wsPORT,host= gstt.wwwIP)
|
||||
plugins.Init(wserver)
|
||||
wserver.set_fn_new_client(new_client)
|
||||
wserver.set_fn_client_left(client_left)
|
||||
wserver.set_fn_message_received(message_received)
|
||||
|
||||
print("")
|
||||
log.info("Resetting all Homographies...")
|
||||
for laserid in range(0,gstt.LaserNumber):
|
||||
homographyp.newEDH(laserid)
|
||||
|
||||
#midi3.check()
|
||||
# plugins autostart
|
||||
print("")
|
||||
#print("")
|
||||
log.info("Plugins startup...")
|
||||
|
||||
if gstt.autostart != "":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue