minor changes and fixes, adjusted frontend

This commit is contained in:
katsu 2025-06-26 14:14:19 +02:00
parent d00651a66c
commit acc38950e7
11 changed files with 99 additions and 121 deletions

View file

@ -7,12 +7,12 @@ import sys
#GLOBALS
room = "undefined"
position = "glavni"
barcoIP = "undefined"
telnetPort = 3023
mqttPort = 1883
mqttIP = 'localhost'
room: str
barcoPosition: str
barcoIP: str
telnetPort: int
mqttPort: int
mqttIP: str
cmdMap = {
'power': 'POWR',
@ -23,11 +23,11 @@ reverseCmdMap = {v: k for k, v in cmdMap.items()}
def parse_barco_response(raw: str):
global room, position
global room, barcoPosition
raw = raw[1:-1] # strip square brackets
#print(raw)
if raw.startswith("ERR"):
print("Projector" + room + " " + position + " returned" + raw)
print("Projector" + room + " " + barcoPosition + " returned" + raw)
return None # TODO parse type error - "disabled control" is special case which shouldnt normally happen
cmd, status = raw.split("!", maxsplit=2)
#print(cmd + " " + status)
@ -40,7 +40,7 @@ async def barco_telnet_command(client, writer, select: str):
global room
onSub = f"{room}/projectors/{select}/#"
#print('TEST', onSub)
onMatch = f"{room}/projectors/{select}/command/+"
onMatch = f"{room}/projectors/{select}/command/+" #TODO should be set?
await client.subscribe(onSub)
#async with client.messages as msgs:
async for mesg in client.messages:
@ -66,7 +66,7 @@ async def barco_telnet_read_status(client, reader, select: str):
raw_response: str = output.decode().strip() # strip not necessary? needed for local netcat testing though
print("Received: " + raw_response + " from Barco (" + select + ')')
parsed = parse_barco_response(raw_response)
if parsed == None:
if parsed is None:
continue #TODO alert for errors
print(f"Updating topic [{parsed[0]}] with value [{parsed[1]}]")
await client.publish(f"{room}/projectors/{select}/status/{parsed[0]}", payload=parsed[1])
@ -79,7 +79,7 @@ async def barco_telnet_query_status(writer, select: str):
writer.write(f"[{val}?]" + '\r\n') # TODO test if funny CRLF necessary (it probably gets ignored)
await asyncio.sleep(0.2) # sleep between writes necessary, otherwise it gets confused.
# simultaneous commands from control could break this? TODO fix later
await asyncio.sleep(30) # TODO find appropriate period
await asyncio.sleep(10) # TODO find appropriate period
# async def shell(reader, writer):
@ -102,8 +102,11 @@ async def main():
g62Barcos = {k: v for k,v in conf["barco_G62"].items()}
currentBarco = g62Barcos[barcoPosition]
barcoIP = currentBarco['ip']
telnetPort = currentBarco["port"]
room = conf["global"]["room"]
mqttPort = conf["global"]["mqttPort"]
mqttIP = conf["global"]["mqttIp"]
barcoReader, barcoWriter = await telnetlib3.open_connection(barcoIP, telnetPort)
async with aiomqtt.Client(mqttIP, mqttPort) as client: