added raw messages and a simple python "mqtt decoder"

This commit is contained in:
Christian Lind Vie Madsen
2026-06-15 10:54:20 +02:00
parent 75c15c71ec
commit 9519b64a52
3 changed files with 125 additions and 10 deletions

View File

@@ -15,7 +15,7 @@ import matplotlib.pyplot as plt
MQTT_BROKER = "s960411f.ala.eu-central-1.emqxsl.com"
MQTT_PORT = 8883
MQTT_USER = "cma"
MQTT_PASS = "cmatest"
MQTT_PASS = "testcma"
TOPIC = "can/raw"
@@ -29,6 +29,7 @@ candidates = defaultdict(list)
# MQTT callback
# ----------------------------
def on_message(client, userdata, msg):
try:
data = json.loads(msg.payload.decode())
@@ -39,9 +40,14 @@ def on_message(client, userdata, msg):
timestamp = data.get("ts", time.time())
history[can_id].append((timestamp, payload))
if can_id != 0x70D and can_id != 0x1CD:
print("ID:", hex(can_id), "Data:", payload)
except Exception as e:
print("Parse error:", e)
# ----------------------------
@@ -116,9 +122,10 @@ def plot_sensor(can_id, byte_index):
client = mqtt.Client()
client.username_pw_set(MQTT_USER, MQTT_PASS)
client.on_message = on_message
client.tls_set(ca_certs='./server-ca.crt')
client.connect(MQTT_BROKER, MQTT_PORT, 60)
client.subscribe(TOPIC)
client.subscribe(TOPIC,qos=1)
client.loop_start()
@@ -132,13 +139,13 @@ plt.ion()
while True:
time.sleep(5)
print_candidates()
# print_candidates()
# try plotting strongest candidate (if any)
sensors = detect_sensor_like_signals()
# sensors = detect_sensor_like_signals()
for can_id, signals in sensors.items():
if signals:
byte_index = signals[0][0]
plot_sensor(can_id, byte_index)
break
# for can_id, signals in sensors.items():
# if signals:
# byte_index = signals[0][0]
# plot_sensor(can_id, byte_index)
# break