|
@ -12,22 +12,25 @@ from can import Bus, BusState, Logger |
|
|
|
|
|
|
|
|
import paho.mqtt.client as mqtt |
|
|
import paho.mqtt.client as mqtt |
|
|
|
|
|
|
|
|
sub_topic = "roll" |
|
|
sub_topic = "shutter" |
|
|
aliases = { |
|
|
aliases = { |
|
|
'Esszimmer': 'EZ', |
|
|
'Esszimmer_Garten': 'EZ_G', |
|
|
|
|
|
'Esszimmer_Nachbar': 'EZ_N', |
|
|
'Wohnzimmer1': 'WZ1', |
|
|
'Wohnzimmer1': 'WZ1', |
|
|
'Wohnzimmer2': 'WZ2', |
|
|
'Wohnzimmer2': 'WZ2', |
|
|
'Wohnzimmer3': 'WZ3', |
|
|
'Wohnzimmer3': 'WZ3', |
|
|
'Wohnzimmer4': 'WZ4', |
|
|
'Wohnzimmer4': 'WZ4', |
|
|
} |
|
|
} |
|
|
event_map = { |
|
|
event_map = { |
|
|
|
|
|
'stop': 0, |
|
|
'off': 0, |
|
|
'off': 0, |
|
|
'up': 1, |
|
|
'up': 1, |
|
|
'down': 2 |
|
|
'down': 2 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
coil_map = { |
|
|
coil_map = { |
|
|
'EZ': [ 0x03, 0x04 , 0x03, 0x05 ], |
|
|
# up , down |
|
|
|
|
|
'EZ_G': [ 0x03, 0x04 , 0x03, 0x05 ], |
|
|
|
|
|
'EZ_N': [ 0x03, 0x06 , 0x03, 0x08 ], |
|
|
'WZ1': [ 0x00, 0x01 , 0x00, 0x01 ], |
|
|
'WZ1': [ 0x00, 0x01 , 0x00, 0x01 ], |
|
|
'WZ2': [ 0x00, 0x01 , 0x00, 0x01 ], |
|
|
'WZ2': [ 0x00, 0x01 , 0x00, 0x01 ], |
|
|
'WZ3': [ 0x00, 0x01 , 0x00, 0x01 ], |
|
|
'WZ3': [ 0x00, 0x01 , 0x00, 0x01 ], |
|
@ -75,11 +78,11 @@ def on_message(mcp_mqtt, userdata, msg): |
|
|
data=m_decode |
|
|
data=m_decode |
|
|
sub=msg.topic[len(sub_topic)+1:] |
|
|
sub=msg.topic[len(sub_topic)+1:] |
|
|
event=event_map[data] |
|
|
event=event_map[data] |
|
|
if event is not None: # it's 0,1,2 |
|
|
|
|
|
coils={ |
|
|
coils={ |
|
|
'up': [ coil_map[sub][0], coil_map[sub][1] ], |
|
|
'up': [ coil_map[sub][0], coil_map[sub][1] ], |
|
|
'down': [ coil_map[sub][2], coil_map[sub][3] ] |
|
|
'down': [ coil_map[sub][2], coil_map[sub][3] ] |
|
|
} |
|
|
} |
|
|
|
|
|
if event is not None: # it's 0,1,2 |
|
|
for key, value in coils.items(): |
|
|
for key, value in coils.items(): |
|
|
msg_id=con(msg_dst=value[0],msg_cmd=0) |
|
|
msg_id=con(msg_dst=value[0],msg_cmd=0) |
|
|
msg_data=[value[1]] |
|
|
msg_data=[value[1]] |
|
@ -94,8 +97,8 @@ def on_message(mcp_mqtt, userdata, msg): |
|
|
logging.error("Error sending can message {%s}: %s" % (m, e)) |
|
|
logging.error("Error sending can message {%s}: %s" % (m, e)) |
|
|
print("data sent to CAN",m) |
|
|
print("data sent to CAN",m) |
|
|
if event is not 0: |
|
|
if event is not 0: |
|
|
print("turning on", coil) |
|
|
addr = coils[data] |
|
|
addr = coils[event-1] |
|
|
print("turning on: ",addr[0],addr[1]) |
|
|
msg_id=con(msg_dst=addr[0],msg_cmd=1) |
|
|
msg_id=con(msg_dst=addr[0],msg_cmd=1) |
|
|
msg_data=[addr[1]] |
|
|
msg_data=[addr[1]] |
|
|
print(msg_data) |
|
|
print(msg_data) |