Browse Source

added some tools

root 5 months ago
parent
commit
42db319ae9
5 changed files with 594 additions and 0 deletions
  1. 85
    0
      tools/can2mqtt.py
  2. 63
    0
      tools/canfixer.py
  3. 175
    0
      tools/light2can.py
  4. 130
    0
      tools/roll2can.py
  5. 141
    0
      tools/sunevents2can.py

+ 85
- 0
tools/can2mqtt.py View File

@@ -0,0 +1,85 @@
1
+#!/usr/bin/env python3
2
+from __future__ import absolute_import, print_function
3
+
4
+import sys
5
+import argparse
6
+import socket
7
+from datetime import datetime
8
+
9
+import can
10
+from can import Bus, BusState, Logger
11
+
12
+import paho.mqtt.client as mqtt
13
+
14
+def decon(msg_id):
15
+   msg_prio=msg_id>>26
16
+   msg_type=(msg_id>>24) & 0x03
17
+   msg_dst=(msg_id>>16) & 0xFF
18
+   msg_src=(msg_id>>8) & 0xFF
19
+   msg_cmd=msg_id & 0xFF
20
+   print("prio: ", hex(msg_prio),"type: ", hex(msg_type)," dst: ", hex(msg_dst)," src: ", hex(msg_src)," cmd: ",hex(msg_cmd))
21
+   return [msg_prio, msg_type, msg_dst, msg_src, msg_cmd]
22
+
23
+def on_connect(mcp_mqtt, userdata, flags, rc):
24
+    print("Connected with result code "+str(rc))
25
+
26
+    # Subscribing in on_connect() means that if we lose the connection and
27
+    # reconnect then subscriptions will be renewed.
28
+    mcp_mqtt.subscribe("can/raw")
29
+    mcp_mqtt.subscribe("ctest/#")
30
+
31
+def on_message(mcp_mqtt, userdata, msg):
32
+    local_bus=userdata
33
+    topic=msg.topic
34
+    print("data Received topic: ", topic)
35
+    m_decode=str(msg.payload.decode("utf-8","ignore"))
36
+    print("data Received",m_decode)
37
+    msg_id=int(m_decode.split('#')[0],16)
38
+
39
+    msg_data=int(m_decode.split('#')[1],16)
40
+    print(msg_data)
41
+    m = can.Message(arbitration_id=msg_id,
42
+          data=[msg_data],
43
+          extended_id=True)
44
+    try:
45
+        local_bus.send(m)
46
+    except BaseException as e:
47
+        logging.error("Error sending can message {%s}: %s" % (m, e))
48
+    print("data sent to CAN",m)
49
+def main():
50
+    verbosity = 2
51
+
52
+    logging_level_name = ['critical', 'error', 'warning', 'info', 'debug', 'subdebug'][min(5, verbosity)]
53
+    can.set_logging_level(logging_level_name)
54
+
55
+    can_filters = []
56
+    config = {"can_filters": can_filters, "single_handle": True}
57
+    config["interface"] = "socketcan"
58
+    config["bitrate"] = 125000
59
+    bus = Bus("can1", **config)
60
+
61
+    print('Connected to {}: {}'.format(bus.__class__.__name__, bus.channel_info))
62
+    print('Can Logger (Started on {})\n'.format(datetime.now()))
63
+
64
+    mcp_mqtt = mqtt.Client()
65
+    mcp_mqtt.on_connect = on_connect
66
+    mcp_mqtt.on_message = on_message
67
+    mcp_mqtt.user_data_set(bus)
68
+    mcp_mqtt.connect("mcp", 1883, 60)
69
+
70
+    try:
71
+        while True:
72
+            mcp_mqtt.loop_start()
73
+            msg = bus.recv(1)
74
+            if msg is not None:
75
+               de=decon(msg.arbitration_id)
76
+               m= { "prio": hex(de[0]), "type": hex(de[1]), "dst": hex(de[2]), "src": hex(de[3]), "cmd": hex(de[4]), "data": "".join("%02x" % b for b in msg.data) }
77
+               print(m) 
78
+               mcp_mqtt.publish("can/rx", str(m))	
79
+    except KeyboardInterrupt:
80
+        pass
81
+    finally:
82
+        bus.shutdown()
83
+
84
+if __name__ == "__main__":
85
+    main()

+ 63
- 0
tools/canfixer.py View File

@@ -0,0 +1,63 @@
1
+#!/usr/bin/env python3
2
+# coding: utf-8
3
+
4
+
5
+from __future__ import absolute_import, print_function
6
+
7
+import sys
8
+import argparse
9
+import socket
10
+from datetime import datetime
11
+
12
+import can
13
+from can import Bus, BusState, Logger
14
+
15
+
16
+def decon(msg_id):
17
+   msg_prio=msg_id>>26
18
+   msg_type=(msg_id>>24) & 0x03
19
+   msg_dst=(msg_id>>16) & 0xFF
20
+   msg_src=(msg_id>>8) & 0xFF
21
+   msg_cmd=msg_id & 0xFF
22
+   print("prio: ", hex(msg_prio),"type: ", hex(msg_type)," dst: ", hex(msg_dst)," src: ", hex(msg_src)," cmd: ",hex(msg_cmd))
23
+   return [msg_prio, msg_type, msg_dst, msg_src, msg_cmd]
24
+
25
+
26
+def main():
27
+    verbosity = 2
28
+
29
+    logging_level_name = ['critical', 'error', 'warning', 'info', 'debug', 'subdebug'][min(5, verbosity)]
30
+    can.set_logging_level(logging_level_name)
31
+
32
+    can_filters = []
33
+    config = {"can_filters": can_filters, "single_handle": True}
34
+    config["interface"] = "socketcan"
35
+    config["bitrate"] = 125000
36
+    bus = Bus("can1", **config)
37
+
38
+    print('Connected to {}: {}'.format(bus.__class__.__name__, bus.channel_info))
39
+    print('Can Logger (Started on {})\n'.format(datetime.now()))
40
+
41
+    try:
42
+        while True:
43
+            msg = bus.recv(1)
44
+            if msg is not None:
45
+               de=decon(msg.arbitration_id)
46
+               m= { "prio": hex(de[0]), "type": hex(de[1]), "dst": hex(de[2]), "src": hex(de[3]), "cmd": hex(de[4]), "target": hex(msg.data[0]) }
47
+               if de[2] is 3 and msg.data[0] is 3 and de[1] is 0 and de[3] is 3 and de[4] is 3 :
48
+                 print(m) 
49
+                 m = can.Message(arbitration_id=0x0C030900,
50
+                     data=[3],
51
+                     extended_id=True)
52
+                 try:
53
+                   bus.send(m)
54
+                 except BaseException as e:
55
+                   logging.error("Error sending can message {%s}: %s" % (m, e))
56
+
57
+    except KeyboardInterrupt:
58
+        pass
59
+    finally:
60
+        bus.shutdown()
61
+
62
+if __name__ == "__main__":
63
+    main()

+ 175
- 0
tools/light2can.py View File

@@ -0,0 +1,175 @@
1
+#!/usr/bin/env python3 
2
+
3
+from __future__ import absolute_import, print_function
4
+
5
+import sys
6
+import argparse
7
+import socket
8
+from datetime import datetime
9
+
10
+import can
11
+from can import Bus, BusState, Logger
12
+
13
+import paho.mqtt.client as mqtt
14
+
15
+sub_topic = "light"
16
+aliases = { 
17
+  'Esszimmer': 'EZ',
18
+  'Esszimmer oben': 'EZ',
19
+  'Küche': 'K',
20
+  'Wohnzimmer1': 'WZ1',
21
+  'Wohnzimmer2': 'WZ2',
22
+  'Wohnzimmer Nord': 'WZ1',
23
+  'Wohnzimmer Süd': 'WZ2',
24
+  'Wohnzimmer Tür': 'WZ1',
25
+  'Wohnzimmer TV': 'WZ2',
26
+  'Wohnzimmer Fernseher': 'WZ2',
27
+  'Bad Decke': 'B1',
28
+  'Bad Spiegel': 'B2',
29
+  'Bjarne': 'K1',
30
+  'Inka': 'K2',
31
+  'Schlafzimmer': 'SCH',
32
+  'Flur EG': 'FE',
33
+  'Flur unten': 'FE',
34
+  'Flur OG': 'FO',
35
+  'Flur oben': 'FO',
36
+  'Treppe EG': 'TRE',
37
+  'Treppe unten': 'TRE',
38
+  'Treppe OG': 'TRO',
39
+  'Treppe oben': 'TRO'
40
+}
41
+light_map = { 
42
+  'EZ': [ 0x03, 0x01 ],
43
+  'K': [ 0x03, 0x02 ],
44
+  'WZ1': [ 0x02, 0x01 ],
45
+  'WZ2': [ 0x02, 0x02 ],
46
+  'TER': [ 0x03, 0x03 ],
47
+  'FE': [ 0x03, 0x07 ],
48
+  'TRE': [ 0x02, 0x03 ],
49
+  'FO': [ 0x01, 0x03 ],
50
+  'TRO': [ 0x01, 0x07 ],
51
+  'KI1': [ 0x01, 0x06 ],
52
+  'KI2': [ 0x01, 0x04 ],
53
+  'SCH': [ 0x01, 0x08 ],
54
+  'B1': [ 0x01, 0x01 ],
55
+  'B2': [ 0x01, 0x02 ],
56
+  'ROL_EZ_DOWN': [0x03,0x05],
57
+  'ROL_EZ_UP': [0x03,0x04],
58
+  'EG1': [ 0x02, 0x09 ],
59
+  'EG2': [ 0x03, 0x09 ],
60
+  'OG': [ 0x01, 0x09 ],
61
+  'ALL': [ 0xFF, 0x09 ],
62
+}
63
+cmd_map = {
64
+  'off': 0,
65
+  'on': 1,
66
+  'value': 2,
67
+  'toggle': 3
68
+}
69
+  
70
+
71
+def decon(msg_id):
72
+   msg_prio=msg_id>>26
73
+   msg_type=(msg_id>>24) & 0x03
74
+   msg_dst=(msg_id>>16) & 0xFF
75
+   msg_src=(msg_id>>8) & 0xFF
76
+   msg_cmd=msg_id & 0xFF
77
+#   print("msg_id: ", hex(msg_id), "prio: ", hex(msg_prio),"type: ", hex(msg_type)," dst: ", hex(msg_dst)," src: ", hex(msg_src)," cmd: ",hex(msg_cmd))
78
+   return [msg_prio, msg_type, msg_dst, msg_src, msg_cmd]
79
+
80
+def con(msg_dst,msg_cmd,msg_prio=3,msg_type=0,msg_src=11, ):
81
+   msg_id=(msg_prio<<26) + \
82
+   ((msg_type&0x03)<<24) +\
83
+   ((msg_dst&0xFF)<<16) +\
84
+   ((msg_src&0xFF)<<8) +\
85
+   (msg_cmd&0xFF)
86
+   print("Constructed ID: "+hex(msg_id))
87
+   return msg_id
88
+
89
+def on_connect(mcp_mqtt, userdata, flags, rc):
90
+    print("Connected with result code "+str(rc))
91
+
92
+    # Subscribing in on_connect() means that if we lose the connection and
93
+    # reconnect then subscriptions will be renewed.
94
+    mcp_mqtt.subscribe(sub_topic+"/+")
95
+    print("Subscribed to:"+sub_topic+"/+")
96
+
97
+def on_message(mcp_mqtt, userdata, msg):
98
+    local_bus=userdata
99
+    print("data Received topic: ", msg.topic)
100
+    m_decode=str(msg.payload.decode("utf-8","ignore"))
101
+    print("data Received",m_decode)
102
+    msg_cmd=2
103
+    try:
104
+      value=int(m_decode)
105
+    except ValueError:
106
+      msg_cmd=cmd_map[m_decode]
107
+
108
+    sub=msg.topic[len(sub_topic)+1:]
109
+    light=aliases.get(sub,None)
110
+    if light is None:
111
+      light=sub
112
+    
113
+
114
+    print("substring: "+light) 
115
+    addr = light_map[light]
116
+    msg_id=con(msg_dst=addr[0],msg_cmd=msg_cmd)
117
+    msg_data=[addr[1]] 
118
+    print(msg_data)
119
+    if msg_cmd == 2:
120
+      msg_data.append(value)
121
+    print(msg_data)
122
+    m = can.Message(arbitration_id=msg_id,
123
+        data=msg_data,
124
+        extended_id=True)
125
+    print("going to sent to CAN",m)
126
+    
127
+    try:
128
+        local_bus.send(m)
129
+    except BaseException as e:
130
+        logging.error("Error sending can message {%s}: %s" % (m, e))
131
+    print("data sent to CAN",m)
132
+
133
+
134
+def main():
135
+    verbosity = 2
136
+
137
+    logging_level_name = ['critical', 'error', 'warning', 'info', 'debug', 'subdebug'][min(5, verbosity)]
138
+    can.set_logging_level(logging_level_name)
139
+
140
+    can_filters = []
141
+    config = {"can_filters": can_filters, "single_handle": True}
142
+    config["interface"] = "socketcan"
143
+    config["bitrate"] = 125000
144
+    bus = Bus("can1", **config)
145
+
146
+    print('Connected to {}: {}'.format(bus.__class__.__name__, bus.channel_info))
147
+    print('Can Logger (Started on {})\n'.format(datetime.now()))
148
+
149
+    mcp_mqtt = mqtt.Client()
150
+    mcp_mqtt.on_connect = on_connect
151
+    mcp_mqtt.on_message = on_message
152
+    mcp_mqtt.user_data_set(bus)
153
+    mcp_mqtt.connect("mcp", 1883, 60)
154
+
155
+    try:
156
+      while True:
157
+        mcp_mqtt.loop_start()
158
+        msg = bus.recv(1)
159
+        if msg is not None:
160
+          de=decon(msg.arbitration_id)
161
+          m= { "prio": hex(de[0]), "type": hex(de[1]), "dst": hex(de[2]), "src": hex(de[3]), "cmd": hex(de[4]), "action": hex(msg.data[0]) }
162
+          if de[2]==0 and de[4] == 6:
163
+            print("received state: ", hex(de[3]), hex(msg.data[0]), hex(msg.data[1]))   
164
+            for key in light_map:
165
+              address=light_map[key]
166
+              if address[0] == de[3] and address[1] == msg.data[0]+1:
167
+                 print("light/"+key+" changed to "+str(msg.data[1]))
168
+                 mcp_mqtt.publish("light/"+key+"/state", msg.data[1] , retain=1)	
169
+    except KeyboardInterrupt:
170
+        pass
171
+    finally:
172
+        bus.shutdown()
173
+
174
+if __name__ == "__main__":
175
+    main()

+ 130
- 0
tools/roll2can.py View File

@@ -0,0 +1,130 @@
1
+#!/usr/bin/env python3 
2
+
3
+from __future__ import absolute_import, print_function
4
+
5
+import sys
6
+import argparse
7
+import socket
8
+from datetime import datetime
9
+
10
+import can
11
+from can import Bus, BusState, Logger
12
+
13
+import paho.mqtt.client as mqtt
14
+
15
+sub_topic = "roll"
16
+aliases = { 
17
+  'Esszimmer': 'EZ',
18
+  'Wohnzimmer1': 'WZ1',
19
+  'Wohnzimmer2': 'WZ2',
20
+  'Wohnzimmer3': 'WZ3',
21
+  'Wohnzimmer4': 'WZ4',
22
+}
23
+coil_map = { 
24
+  'EZ':  [ 0x03, 0x04 , 0x03, 0x05 ],
25
+  'WZ1': [ 0x00, 0x01 , 0x00, 0x01 ],
26
+  'WZ2': [ 0x00, 0x01 , 0x00, 0x01 ],
27
+  'WZ3': [ 0x00, 0x01 , 0x00, 0x01 ],
28
+  'WZ4': [ 0x00, 0x01 , 0x00, 0x01 ],
29
+}
30
+cmd_map = {
31
+  'off': 0,
32
+  'on': 1,
33
+  'value': 2,
34
+  'toggle': 3
35
+}
36
+  
37
+
38
+def decon(msg_id):
39
+   msg_prio=msg_id>>26
40
+   msg_type=(msg_id>>24) & 0x03
41
+   msg_dst=(msg_id>>16) & 0xFF
42
+   msg_src=(msg_id>>8) & 0xFF
43
+   msg_cmd=msg_id & 0xFF
44
+   print("msg_id: ", hex(msg_id), "prio: ", hex(msg_prio),"type: ", hex(msg_type)," dst: ", hex(msg_dst)," src: ", hex(msg_src)," cmd: ",hex(msg_cmd))
45
+   return [msg_prio, msg_type, msg_dst, msg_src, msg_cmd]
46
+
47
+def con(msg_dst,msg_cmd,msg_prio=3,msg_type=0,msg_src=11, ):
48
+   msg_id=(msg_prio<<26) + \
49
+   ((msg_type&0x03)<<24) +\
50
+   ((msg_dst&0xFF)<<16) +\
51
+   ((msg_src&0xFF)<<8) +\
52
+   (msg_cmd&0xFF)
53
+   print("Constructed ID: "+hex(msg_id))
54
+   return msg_id
55
+
56
+def on_connect(mcp_mqtt, userdata, flags, rc):
57
+    print("Connected with result code "+str(rc))
58
+
59
+    # Subscribing in on_connect() means that if we lose the connection and
60
+    # reconnect then subscriptions will be renewed.
61
+    mcp_mqtt.subscribe(sub_topic+"/+")
62
+    print("Subscribed to:"+sub_topic+"/+")
63
+
64
+def on_message(mcp_mqtt, userdata, msg):
65
+    local_bus=userdata
66
+    print("data Received topic: ", msg.topic)
67
+    m_decode=str(msg.payload.decode("utf-8","ignore"))
68
+    print("data Received",m_decode)
69
+    msg_cmd=2
70
+    try:
71
+      value=int(m_decode)
72
+    except ValueError:
73
+      msg_cmd=cmd_map[m_decode]
74
+
75
+    sub=msg.topic[len(sub_topic)+1:]
76
+    roll=aliases.get(sub,None)
77
+    if roll is None:
78
+      roll=sub
79
+
80
+    print("substring: "+roll) 
81
+    addr = light_map[light]
82
+    msg_id=con(msg_dst=addr[0],msg_cmd=msg_cmd)
83
+    msg_data=[addr[1]] 
84
+    print(msg_data)
85
+    if msg_cmd == 2:
86
+      msg_data.append(value)
87
+    print(msg_data)
88
+    m = can.Message(arbitration_id=msg_id,
89
+        data=msg_data,
90
+        extended_id=True)
91
+    print("going to sent to CAN",m)
92
+    
93
+    try:
94
+        local_bus.send(m)
95
+    except BaseException as e:
96
+        logging.error("Error sending can message {%s}: %s" % (m, e))
97
+    print("data sent to CAN",m)
98
+
99
+
100
+def main():
101
+    verbosity = 2
102
+
103
+    logging_level_name = ['critical', 'error', 'warning', 'info', 'debug', 'subdebug'][min(5, verbosity)]
104
+    can.set_logging_level(logging_level_name)
105
+
106
+    can_filters = []
107
+    config = {"can_filters": can_filters, "single_handle": True}
108
+    config["interface"] = "socketcan"
109
+    config["bitrate"] = 125000
110
+    bus = Bus("can1", **config)
111
+
112
+    print('Connected to {}: {}'.format(bus.__class__.__name__, bus.channel_info))
113
+    print('Can Logger (Started on {})\n'.format(datetime.now()))
114
+
115
+    mcp_mqtt = mqtt.Client()
116
+    mcp_mqtt.on_connect = on_connect
117
+    mcp_mqtt.on_message = on_message
118
+    mcp_mqtt.user_data_set(bus)
119
+    mcp_mqtt.connect("mcp", 1883, 60)
120
+
121
+    try:
122
+        while True:
123
+            mcp_mqtt.loop_start()
124
+    except KeyboardInterrupt:
125
+        pass
126
+    finally:
127
+        bus.shutdown()
128
+
129
+if __name__ == "__main__":
130
+    main()

+ 141
- 0
tools/sunevents2can.py View File

@@ -0,0 +1,141 @@
1
+#!/usr/bin/env python3
2
+# coding: utf-8
3
+
4
+from __future__ import absolute_import, print_function
5
+
6
+import sys
7
+import argparse
8
+import socket
9
+from datetime import datetime
10
+
11
+import can
12
+from can import Bus, BusState, Logger
13
+
14
+import paho.mqtt.client as mqtt
15
+
16
+topic = "sunevents"
17
+event_map = {
18
+  'sunrise': "up",  
19
+  'night': "down",  
20
+}
21
+coil_map = { 
22
+  'ROL_EZ_DOWN': [0x03,0x05],
23
+  'ROL_EZ_UP': [0x03,0x04]
24
+}
25
+group_map = {
26
+  'up': ['ROL_EZ_UP'], 
27
+  'down': ['ROL_EZ_DOWN'] 
28
+}
29
+cmd_map = {
30
+  'off': 0,
31
+  'on': 1,
32
+  'value': 2,
33
+  'toggle': 3
34
+}
35
+  
36
+
37
+def decon(msg_id):
38
+   msg_prio=msg_id>>26
39
+   msg_type=(msg_id>>24) & 0x03
40
+   msg_dst=(msg_id>>16) & 0xFF
41
+   msg_src=(msg_id>>8) & 0xFF
42
+   msg_cmd=msg_id & 0xFF
43
+#   print("msg_id: ", hex(msg_id), "prio: ", hex(msg_prio),"type: ", hex(msg_type)," dst: ", hex(msg_dst)," src: ", hex(msg_src)," cmd: ",hex(msg_cmd))
44
+   return [msg_prio, msg_type, msg_dst, msg_src, msg_cmd]
45
+
46
+def con(msg_dst,msg_cmd,msg_prio=3,msg_type=0,msg_src=11, ):
47
+   msg_id=(msg_prio<<26) + \
48
+   ((msg_type&0x03)<<24) +\
49
+   ((msg_dst&0xFF)<<16) +\
50
+   ((msg_src&0xFF)<<8) +\
51
+   (msg_cmd&0xFF)
52
+   print("Constructed ID: "+hex(msg_id))
53
+   return msg_id
54
+
55
+def on_connect(mcp_mqtt, userdata, flags, rc):
56
+    print("Connected with result code "+str(rc))
57
+
58
+    # Subscribing in on_connect() means that if we lose the connection and
59
+    # reconnect then subscriptions will be renewed.
60
+    mcp_mqtt.subscribe(topic)
61
+    print("Subscribed to:",topic)
62
+
63
+def on_message(mcp_mqtt, userdata, msg):
64
+    local_bus=userdata
65
+    print("data Received topic: ", msg.topic)
66
+    m_decode=str(msg.payload.decode("utf-8","ignore"))
67
+    print("data Received",m_decode)
68
+    data=m_decode
69
+    event=event_map[data]
70
+    if event is not None:
71
+   #   event=sub
72
+      for key, value in coil_map.items():
73
+        msg_id=con(msg_dst=value[0],msg_cmd=0)
74
+        msg_data=[value[1]] 
75
+        print("turning off: ",key,value[0],value[1])
76
+        m = can.Message(arbitration_id=msg_id,
77
+            data=msg_data,
78
+            extended_id=True)
79
+        print("going to sent to CAN",m)
80
+        try:
81
+          local_bus.send(m)
82
+        except BaseException as e:
83
+          logging.error("Error sending can message {%s}: %s" % (m, e))
84
+        print("data sent to CAN",m)
85
+
86
+      print("Group: ",event) 
87
+      for coil in group_map[event]:  
88
+        print("turning on", coil)
89
+        addr = coil_map[coil]
90
+        msg_id=con(msg_dst=addr[0],msg_cmd=1)
91
+        msg_data=[addr[1]] 
92
+        print(msg_data)
93
+        m = can.Message(arbitration_id=msg_id,
94
+            data=msg_data,
95
+            extended_id=True)
96
+        print("going to sent to CAN",m)
97
+    
98
+        try:
99
+            local_bus.send(m)
100
+        except BaseException as e:
101
+            logging.error("Error sending can message {%s}: %s" % (m, e))
102
+        print("data sent to CAN",m)
103
+
104
+
105
+def main():
106
+    verbosity = 2
107
+
108
+    logging_level_name = ['critical', 'error', 'warning', 'info', 'debug', 'subdebug'][min(5, verbosity)]
109
+    can.set_logging_level(logging_level_name)
110
+
111
+    can_filters = []
112
+    config = {"can_filters": can_filters, "single_handle": True}
113
+    config["interface"] = "socketcan"
114
+    config["bitrate"] = 125000
115
+    bus = Bus("can1", **config)
116
+
117
+    print('Connected to {}: {}'.format(bus.__class__.__name__, bus.channel_info))
118
+    print('Can Logger (Started on {})\n'.format(datetime.now()))
119
+
120
+    mcp_mqtt = mqtt.Client()
121
+    mcp_mqtt.on_connect = on_connect
122
+    mcp_mqtt.on_message = on_message
123
+    mcp_mqtt.user_data_set(bus)
124
+    mcp_mqtt.connect("mcp", 1883, 60)
125
+
126
+    try:
127
+        while True:
128
+            mcp_mqtt.loop_start()
129
+            msg = bus.recv(1)
130
+            if msg is not None:
131
+               de=decon(msg.arbitration_id)
132
+               m= { "prio": hex(de[0]), "type": hex(de[1]), "dst": hex(de[2]), "src": hex(de[3]), "cmd": hex(de[4]), "action": hex(msg.data[0]) }
133
+#               print(m)        
134
+ #              mcp_mqtt.publish("can/rx", str(m))	
135
+    except KeyboardInterrupt:
136
+        pass
137
+    finally:
138
+        bus.shutdown()
139
+
140
+if __name__ == "__main__":
141
+    main()