Skip to content
Snippets Groups Projects
Commit 60afc1ad authored by Johannes Walcher's avatar Johannes Walcher
Browse files

all those small changes

parent 45249e47
No related branches found
No related tags found
No related merge requests found
...@@ -16,17 +16,17 @@ class Babel: ...@@ -16,17 +16,17 @@ class Babel:
self.hbf.subscribe('/haspa/power/requestinfo', self.command_requestinfo) self.hbf.subscribe('/haspa/power/requestinfo', self.command_requestinfo)
self.hbf.subscribe('/haspa/power/status', self.command_requeststatus) self.hbf.subscribe('/haspa/power/status', self.command_requeststatus)
self.ledstrip_states = [[0, 0, 0, 0], [0, 0, 0, 0]] self.ledstrip_states = [[0] * 8, [0] * 8]
self.espids = ['a9495a00', 'c14e5a00'] #self.espids = ['a9495a00', 'c14e5a00']
# new 4 channel ESPs
self.espids = ['f97c7300', 'dfd80b00']
# mapps from (color, id) ==> (self.ledstrip indexes) # mapps from (color, id) ==> (self.ledstrip indexes)
self.idxpair = { self.idxpair = {
# The first one has cold and warm swapped... ('c', 2):(0, 0),
('w', 2):(0, 0), ('w', 2):(0, 1),
('c', 2):(0, 1), ('c', 1):(0, 6),
('w', 1):(0, 2), ('w', 1):(0, 7),
('c', 1):(0, 3),
# This one has cold and warm right
('c', 3):(1, 0), ('c', 3):(1, 0),
('w', 3):(1, 1), ('w', 3):(1, 1),
('c', 4):(1, 2), ('c', 4):(1, 2),
...@@ -55,7 +55,7 @@ class Babel: ...@@ -55,7 +55,7 @@ class Babel:
## The lamp is managed by rupprecht ## The lamp is managed by rupprecht
if lamp in self.rupprecht_map: if lamp in self.rupprecht_map:
msg[self.rupprecht_map[lamp][0]] = int(value) msg[self.rupprecht_map[lamp][0]] = int(value)
self.rupprecht_map[lamp][1] = int(value) self.rupprecht_map[lamp] = (self.rupprecht_map[lamp][0], int(value))
## The lamp is a led strip and needs to be aggregated ## The lamp is a led strip and needs to be aggregated
if lamp.startswith('ledstrip'): if lamp.startswith('ledstrip'):
......
...@@ -54,12 +54,26 @@ class Hackerman: ...@@ -54,12 +54,26 @@ class Hackerman:
async def command_action(self, client, message, _): async def command_action(self, client, message, _):
""" Handle actions like alarm or party """ """ Handle actions like alarm or party """
del client del client
print(message)
if 'action' in message: if 'action' in message:
if message['action'] == 'alarm': if message['action'] == 'alarm':
print("Performing alarm...")
await self.hbf.publish('/haspa/power', {'alarm':1023}) await self.hbf.publish('/haspa/power', {'alarm':1023})
await asyncio.sleep(2) await asyncio.sleep(2)
await self.hbf.publish('/haspa/power', {'alarm':0}) await self.hbf.publish('/haspa/power', {'alarm':0})
elif message['action'] == 'strobo':
for i in range(100):
await self.hbf.publish('/haspa/power', {
'ledstrip-c': 0
})
await asyncio.sleep(0.05)
await self.hbf.publish('/haspa/power', {
'ledstrip-c': 1023
})
await asyncio.sleep(0.03)
elif message['action'] == 'party': elif message['action'] == 'party':
await self.hbf.publish('/haspa/power', { await self.hbf.publish('/haspa/power', {
'alarm':0, 'alarm':0,
......
libconf==1.0.1
paho-mqtt==1.3.1
pyserial==3.4
pyserial-asyncio==0.4
...@@ -92,10 +92,14 @@ class Quigg1000: ...@@ -92,10 +92,14 @@ class Quigg1000:
async def __send_msg(self, msg): async def __send_msg(self, msg):
if self.rupprecht: if self.rupprecht:
print("sending via rupprecht message", msg)
await self.rupprecht.light(msg) await self.rupprecht.light(msg)
await asyncio.sleep(1)
if self.serial: if self.serial:
print("sending via raw message", msg)
try: try:
self.ser.write(str.encode(msg)) self.serial.write(str.encode(msg))
await asyncio.sleep(1)
except serial.SerialException: except serial.SerialException:
print('Serial communication failed.') print('Serial communication failed.')
...@@ -113,6 +117,7 @@ def main(): ...@@ -113,6 +117,7 @@ def main():
default=False, action='store_true') default=False, action='store_true')
args = parser.parse_args() args = parser.parse_args()
loop=asyncio.get_event_loop()
try: try:
s = serial.Serial(args.device, 9600) s = serial.Serial(args.device, 9600)
...@@ -121,7 +126,6 @@ def main(): ...@@ -121,7 +126,6 @@ def main():
exit() exit()
r = Quigg1000(serial=s, loop=loop, code=args.set_code, subaddr=args.addr) r = Quigg1000(serial=s, loop=loop, code=args.set_code, subaddr=args.addr)
loop=asyncio.get_event_loop()
loop.run_until_complete(r.state(args.state, args.debug)) loop.run_until_complete(r.state(args.state, args.debug))
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -52,9 +52,9 @@ class Rupprecht: ...@@ -52,9 +52,9 @@ class Rupprecht:
async def teardown(self): async def teardown(self):
await self.hbf.teardown() await self.hbf.teardown()
async def command_led(self, source, payload, mqttmsg): async def command_led(self, source, msg, mqttmsg):
del source, payload print("having LED command", msg)
msg = json.loads(mqttmsg.payload.decode('utf-8')) del source, mqttmsg
for devid, value in msg.items(): for devid, value in msg.items():
try: try:
if value == 0: if value == 0:
...@@ -68,17 +68,16 @@ class Rupprecht: ...@@ -68,17 +68,16 @@ class Rupprecht:
if msg['open'] and not self.space_is_open: if msg['open'] and not self.space_is_open:
self.space_is_open = True self.space_is_open = True
await self.hbf.publish('/haspa/status', {'haspa':'open'}) await self.hbf.publish('/haspa/status', {'haspa':'open'})
self.rupprecht.text("Status:Open... StuStaNet.e.V....") await self.rupprecht.text("Status:Open... StuStaNet.e.V....")
elif not msg['open'] and self.space_is_open: elif not msg['open'] and self.space_is_open:
self.space_is_open = False self.space_is_open = False
await self.hbf.publish('/haspa/status', {'haspa':'closed'}) await self.hbf.publish('/haspa/status', {'haspa':'closed'})
self.rupprecht.text("Status:Closed... StuStaNet.e.V....") await self.rupprecht.text("Status:Closed... StuStaNet.e.V....")
class RupprechtInterface: class RupprechtInterface:
def __init__(self, serial_port, baudrate=115200, loop=None): def __init__(self, serial_port, baudrate=115200, loop=None):
self.loop = loop or asyncio.get_event_loop() self.loop = loop or asyncio.get_event_loop()
self.button_callbacks = []; self.button_callbacks = [];
coro = serial_asyncio.open_serial_connection(loop=self.loop, url=serial_port, coro = serial_asyncio.open_serial_connection(loop=self.loop, url=serial_port,
...@@ -106,17 +105,31 @@ class RupprechtInterface: ...@@ -106,17 +105,31 @@ class RupprechtInterface:
async def receive_messages(self): async def receive_messages(self):
while True: while True:
line = await self.reader.readline() try:
line = line.strip() print("Waiting for input:")
line = await self.reader.readline()
except serial.SerialException:
print("SerialException, will terminate")
self.loop.cancel()
return
print("Received: ", line)
line = line.decode('ascii').strip()
if str.startswith(line, "BUTTON"): if str.startswith(line, "BUTTON"):
print("Button message")
await self.button_queue.put(line[len("BUTTON"):]) await self.button_queue.put(line[len("BUTTON"):])
else: else:
print("Into data queue")
await self.data_queue.put(line) await self.data_queue.put(line)
print("done")
async def handlecallbacks(self): async def handlecallbacks(self):
await self.send_raw("CONFIG ECHO OFF")
# filter out the last echo # filter out the last echo
await self.data_queue.get() #await self.data_queue.get()
#print("Waiting for message")
#while "READY" != self.data_queue.get():
# pass
#await self.send_raw("CONFIG ECHO OFF", expect_response=False)
print("Rupprecht finally there")
while True: while True:
button_msg = await self.button_queue.get() button_msg = await self.button_queue.get()
...@@ -128,7 +141,7 @@ class RupprechtInterface: ...@@ -128,7 +141,7 @@ class RupprechtInterface:
for callback in self.button_callbacks: for callback in self.button_callbacks:
try: try:
callback(buttons) await callback(buttons)
except Exception as e: except Exception as e:
print("Exception while executing callback for", button_msg , e) print("Exception while executing callback for", button_msg , e)
...@@ -141,8 +154,10 @@ class RupprechtInterface: ...@@ -141,8 +154,10 @@ class RupprechtInterface:
This will wait, until the preceding message has been processed. This will wait, until the preceding message has been processed.
""" """
print("Sending RUPPRECHT message: ", msg)
self.writer.write(msg.encode('ascii')) self.writer.write(msg.encode('ascii'))
if msg[-1] != "\n":
self.writer.write(b"\n")
await self.writer.drain() await self.writer.drain()
if expect_response: if expect_response:
return await self.data_queue.get() return await self.data_queue.get()
......
[Unit] [Unit]
Description=Hauptbahnhof %i-Module Description=Hauptbahnhof %i-Module
After=network.target After=network-online.target
Requires=mosquitto.service
Before=hauptbahnhof.service Before=hauptbahnhof.service
[Service] [Service]
......
[Unit] [Unit]
Description=Hauptbahnhof Hackerspace Control System Description=Hauptbahnhof Hackerspace Control System
Wants=mosquitto.service
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment