small reworks in frontend and scripts, mostly finalized ansible deploy script -- still needs testing
This commit is contained in:
parent
f41dfc4f86
commit
e57f803a52
25 changed files with 440 additions and 90 deletions
|
@ -3,14 +3,16 @@ import socket
|
|||
import aiomqtt
|
||||
import telnetlib3
|
||||
import toml
|
||||
from socket import gethostname
|
||||
import sys
|
||||
|
||||
mainBarcoIP = '192.168.192.12'
|
||||
sideBarcoIP = '192.168.192.13'
|
||||
#GLOBALS
|
||||
|
||||
# TODO all the checks and stuff
|
||||
# TODO MAKE THIS CONFIGURALBE
|
||||
room = "undefined"
|
||||
position = "undefined"
|
||||
barcoIP = "undefined"
|
||||
telnetPort = 3023
|
||||
mqttPort = 1883
|
||||
mqttIP = 'localhost'
|
||||
|
||||
cmdMap = {
|
||||
'power': 'POWR',
|
||||
|
@ -31,11 +33,13 @@ def parse_barco_response(raw: str):
|
|||
status = '1' if status == '01' else '0'
|
||||
return cmd, status
|
||||
|
||||
#TODO MAKE THESE USE GLOBAL INSTEAD OF PASSING BARCO POSITION IN MAIN
|
||||
|
||||
async def barco_telnet_command(client, writer, select: str):
|
||||
onSub = f"p01/projectors/{select}/#"
|
||||
global room
|
||||
onSub = f"{room}/projectors/{select}/#"
|
||||
#print('TEST', onSub)
|
||||
onMatch = f"p01/projectors/{select}/command/+"
|
||||
onMatch = f"{room}/projectors/{select}/command/+"
|
||||
await client.subscribe(onSub)
|
||||
#async with client.messages as msgs:
|
||||
async for mesg in client.messages:
|
||||
|
@ -55,6 +59,7 @@ async def barco_telnet_command(client, writer, select: str):
|
|||
|
||||
|
||||
async def barco_telnet_read_status(client, reader, select: str):
|
||||
global room
|
||||
while True:
|
||||
output = await reader.readuntil(b']')
|
||||
raw_response: str = output.decode().strip() # strip not necessary? needed for local netcat testing though
|
||||
|
@ -63,7 +68,7 @@ async def barco_telnet_read_status(client, reader, select: str):
|
|||
if parsed == None:
|
||||
continue #TODO alert for errors
|
||||
print(f"Updating topic [{parsed[0]}] with value [{parsed[1]}]")
|
||||
await client.publish(f"p01/projectors/{select}/status/{parsed[0]}", payload=parsed[1])
|
||||
await client.publish(f"{room}/projectors/{select}/status/{parsed[0]}", payload=parsed[1])
|
||||
|
||||
|
||||
async def barco_telnet_query_status(writer, select: str):
|
||||
|
@ -84,23 +89,25 @@ async def barco_telnet_query_status(writer, select: str):
|
|||
# await asyncio.gather(task_status_query, task_status_reader, task_control)
|
||||
|
||||
|
||||
async def main(mqttIP=localhost, barcoIP=localhost, mqttPort=1883, telnetPort=3023):
|
||||
conf = toml.load('config.toml')
|
||||
barco
|
||||
# mainBarcoIP = conf[gethostname()]['projektor_glavni']
|
||||
# sideBarcoIP = conf[gethostname()]['projektor_stranski']
|
||||
mainReader, mainWriter = await telnetlib3.open_connection(barcoIP, telnetPort)
|
||||
#sideReader, sideWriter = await telnetlib3.open_connection('localhost', 3024)
|
||||
async with aiomqtt.Client(mqttIP, mqttPort) as client:
|
||||
task_status_query_main = asyncio.create_task(barco_telnet_query_status(mainWriter, 'glavni'))
|
||||
task_status_reader_main = asyncio.create_task(barco_telnet_read_status(client, mainReader, 'glavni'))
|
||||
task_control_main = asyncio.create_task(barco_telnet_command(client, mainWriter, 'glavni'))
|
||||
#task_status_query_side = asyncio.create_task(barco_telnet_query_status(sideWriter, 'stranski'))
|
||||
#task_status_reader_side = asyncio.create_task(barco_telnet_read_status(client, sideReader, 'stranski'))
|
||||
#task_control_side = asyncio.create_task(barco_telnet_command(client, sideWriter, 'stranski'))
|
||||
async def main():
|
||||
global barcoPosition, barcoIP, telnetPort, mqttIP, mqttPort
|
||||
if len(sys.argv) < 2:
|
||||
sys.exit("No position provided")
|
||||
else:
|
||||
barcoPosition = sys.argv[1]
|
||||
|
||||
await asyncio.gather(task_status_query_main, task_status_reader_main, task_control_main)
|
||||
#task_status_query_side, task_status_reader_side, task_control_side)
|
||||
conf = toml.load('./config.toml')
|
||||
g62Barcos = {k: v for k,v in barcos["barco_G62"].items()}
|
||||
currentBarco = newBarcos[barcoPosition]
|
||||
barcoIP = currentBarco['ip']
|
||||
|
||||
barcoReader, barcoWriter = await telnetlib3.open_connection(barcoIP, telnetPort)
|
||||
async with aiomqtt.Client(mqttIP, mqttPort) as client:
|
||||
task_status_query_barco = asyncio.create_task(barco_telnet_query_status(barcoWriter, barcoPosition))
|
||||
task_status_reader_barco = asyncio.create_task(barco_telnet_read_status(client, barcoReader, barcoPosition))
|
||||
task_control_barco = asyncio.create_task(barco_telnet_command(client, barcoWriter, barcoPosition))
|
||||
|
||||
await asyncio.gather(task_status_query_barco, task_status_reader_barco, task_control_barco)
|
||||
|
||||
|
||||
### fuj to, ne tk delat
|
Loading…
Add table
Add a link
Reference in a new issue