This repository was archived by the owner on May 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalysisDashControllerCompanion.py
More file actions
97 lines (74 loc) · 2.71 KB
/
AnalysisDashControllerCompanion.py
File metadata and controls
97 lines (74 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import paho.mqtt.client as mqtt # import the client1
import json
global gear
global debug
global telemetry
global accmode
global datalog
global lapnum
gear = 0
debug = 0
telemetry = 0
accmode = 0
datalog = 0
lapnum = 0
# Printing Received Data Function
def on_message(client, userdata, message):
try:
global gear
global debug
global telemetry
global accmode
global datalog
global lapnum
if message.topic == "data/formatted/gear":
jsonMessage = json.loads(message.payload.decode("utf-8"))
gear = int(jsonMessage['value'])
elif message.topic == "data/formatted/debug_mode":
jsonMessage = json.loads(message.payload.decode("utf-8"))
debug = jsonMessage['value']
elif message.topic == "data/formatted/telemetria_on-off":
jsonMessage = json.loads(message.payload.decode("utf-8"))
telemetry = jsonMessage['value']
elif message.topic == "data/formatted/auto_acc_flag":
jsonMessage = json.loads(message.payload.decode("utf-8"))
accmode = jsonMessage['value']
elif message.topic == "data/formatted/datalog_on-off":
jsonMessage = json.loads(message.payload.decode("utf-8"))
datalog = jsonMessage['value']
elif message.topic == "data/formatted/lapnumber":
jsonMessage = json.loads(message.payload.decode("utf-8"))
lapnum = jsonMessage['value']
print()
print()
print()
print()
print()
print()
print()
print("############################################ ")
print()
print("gear : ", gear)
print("debug : ", debug)
print("telemetry : ", telemetry)
print("accmode : ", accmode)
print("datalog : ", datalog)
print("lapnumber : ", lapnum)
except:
print("error")
########################################
print("creating new instance")
client = mqtt.Client("Analysis companion")
client.on_message = on_message # attach function to callback
print("connecting to broker")
client.connect("localhost") # connect to broker
# SUBSCRIPTIONS
# to subscribe just type:
# client.subscribe("data/formatted/ <formatted data Channel-name> ")
client.subscribe("data/formatted/gear") # subscribing to gear Channel
client.subscribe("data/formatted/auto_acc_flag")
client.subscribe("data/formatted/debug_mode")
client.subscribe("data/formatted/datalog_on-off")
client.subscribe("data/formatted/telemetria_on-off")
client.subscribe("data/formatted/lapnumber")
client.loop_forever() # start the loop