added systemd service config files and misc changes, still need to finish writing the reworked tse box controller

This commit is contained in:
0xEmm 2024-11-07 17:07:29 +01:00
parent 81218eb21a
commit e595fb97ce
10 changed files with 131 additions and 8 deletions

16
barco.service Normal file
View file

@ -0,0 +1,16 @@
[Unit]
Description=Barco projector control
After=mqtt_init.service
[Service]
ExecStart=/usr/bin/python3 /home/rpi/barco_telnet_control.py
User=rpi
Group=rpi
Type=simple
Restart=always
[Install]
WantedBy=mqtt_init.service

View file

@ -32,9 +32,9 @@ def parse_barco_response(raw: str):
async def barco_telnet_command(client, writer, select: str):
onSub = f"p1/projektorji/{select}/#"
print('TEST', onSub)
onMatch = f"p1/projektorji/{select}/ukaz/+"
onSub = f"p1/projectors/{select}/#"
#print('TEST', onSub)
onMatch = f"p1/projectors/{select}/command/+"
await client.subscribe(onSub)
async with client.messages() as msgs:
async for mesg in msgs:
@ -46,7 +46,7 @@ async def barco_telnet_command(client, writer, select: str):
# print("test")
cmd = mesg.topic.value.split("/")[-1]
#val = '1' if mesg.payload.decode() == 'ON' else '0'
val = '1' if mesg.payload.decode() == 'ON' else '0'
val = '1' if mesg.payload.decode() == 'ON' else '0' # refactor to direct 0 and 1
barcoCmd = f"[{cmdMap[cmd]}{val}]"
print("Received: [" + mesg.topic.value + "] payload: [" + mesg.payload.decode() + "]")
print("Sending command to Barco: " + barcoCmd)
@ -62,7 +62,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"p1/projektorji/{select}/status/{parsed[0]}", payload=parsed[1])
await client.publish(f"p1/projectors/{select}/status/{parsed[0]}", payload=parsed[1])
async def barco_telnet_query_status(writer, select: str):

8
eth0.notwork Normal file
View file

@ -0,0 +1,8 @@
[Match]
Name=eth0
[Network]
Address=192.168.192.42
Gateway=192.168.192.1

13
extron_audio.service Normal file
View file

@ -0,0 +1,13 @@
[Unit]
Description=Extron audio matrix control
After=mqtt_init.service
[Service]
ExecStart=/usr/bin/python3 /home/rpi/extron_audio_matrix_telnet_control.py
Type=simple
Restart=always
[Install]
WantedBy=mqtt_init.service

3
interfaces.save Normal file
View file

@ -0,0 +1,3 @@
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source /etc/network/interfaces.d/*

11
mqtt_init.service Normal file
View file

@ -0,0 +1,11 @@
[Unit]
Description=Sets up MQTT topics
After=multi-user.target
[Service]
ExecStart =/usr/bin/python3 /home/rpi/mqtt_init_topics.py
Type=simple
[Install]
WantedBy=multi-user.target

12
projector_motors.service Normal file
View file

@ -0,0 +1,12 @@
[Unit]
Description=Control for projector motors
After=mqtt_init.service
[Service]
ExecStart=/usr/bin/python3 /home/rpi/projector_motors.py
Restart=always
Type=simple
[Install]
WantedBy=mqtt_init.service

15
tse_box.service Normal file
View file

@ -0,0 +1,15 @@
[Unit]
Description=TSE serial control
After=mqtt_init.service
[Service]
ExecStart=/usr/bin/python3 /home/rpi/tse_serial_controler.py /home/rpi/tse_serial_interpreter.py
Type=simple
Restart=always
User=rpi
Group=rpi
[Install]
WantedBy=mqtt_init.service

13
tse_releji_mapping.txt Normal file
View file

@ -0,0 +1,13 @@
1 - sistem
2 - ozvocenje
3 - projektorji
4 - ?
5 - platno 1 dol
6 - platno 1 gor
7 - platno 2 dol
8 - platno 2 gor
9 - sencilo dol
10 - sencilo gor
11 - ?
12 - ?

View file

@ -4,8 +4,10 @@ import aioserial
import aiomqtt
from tse_serial_interpreter import *
room = 'p1' #TODO make be do get fronm file of configuration
aser: aioserial.AioSerial = aioserial.AioSerial(
port='/dev/cu.usbserial-14240',
port='/dev/cu.usbserial-14240', #TODO not hardcode it
baudrate=1200,
parity=serial.PARITY_NONE,
bytesize=serial.EIGHTBITS,
@ -13,13 +15,43 @@ aser: aioserial.AioSerial = aioserial.AioSerial(
)
# TODO adjust serial on actual TSE interface
mapping = {
"master": 1,
"audio": 2,
"projectors": 3,
"platno_glavni_dol": 5,
"platno_glavni_gor": 6,
"platno_stranski_dol": 7,
"platno_stranski_gor": 8,
"sencilo_dol": 9,
"sencilo_gor": 10
#ostalo reserved
}
reverse_lookup = {v: k for k, v in mapping.items()}
def parse_topic_from_mqtt(topic: str):
topicArr = topic.split()
async def task_status2mqtt(statusClient: aiomqtt.Client):
while True:
data = await aser.read_until_async()
data = data.decode(errors='ignore').strip()
print("TSE box sent: " + data)
relState = resp_to_relay_state(data)
publishTopic = f"p1/tseRelays/{relState.relay_id}/status"
command = reverse_lookup[relState.relay_id]
action = relState.state
#TODO havent figured out a clean way to
# get out the action from topic yet as they are
# not always on the same level
# probably just do it the most straight forward way
# with some more code
publishTopic = f"{room}/"
publishPayload = "ON" if relState.state else "OFF"
print("Publishing [" + publishPayload + "] to topic [" + publishTopic + "]")
await statusClient.publish(publishTopic, payload=publishPayload)
@ -34,7 +66,7 @@ async def task_command2serial(controlClient: aiomqtt.Client):
msgTopic = mesg.topic.value
cmnd = mesg.payload.decode()
print("Received: [" + msgTopic + "] payload: [" + cmnd + "]")
relay = int(mesg.topic.value.split("/")[-2])
relay = int(mesg.topic.value.split("/")[-2]) #TODO different by case
cmnd = cmnd == "ON"
relState = RelayState(relay, cmnd)
setRelay = relay_state_to_cmd(relState)