From 8ea7f33fbdbf369541aafbeba59248347dd35652 Mon Sep 17 00:00:00 2001 From: Laurent Date: Sat, 27 Dec 2025 14:45:21 +0100 Subject: [PATCH] Fix lora receiver --- esp32-lora/lora_receiver.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/esp32-lora/lora_receiver.py b/esp32-lora/lora_receiver.py index 81dd87fa..fd73e762 100644 --- a/esp32-lora/lora_receiver.py +++ b/esp32-lora/lora_receiver.py @@ -1,8 +1,21 @@ import serial +import json +import re -ser = serial.Serial('/dev/ttyUSB1', 57600, timeout=1) +ser = serial.Serial('/dev/ttyUSB1', 9600, timeout=1) + +# Regex to capture JSON object +json_pattern = re.compile(r'\{.*\}') while True: - line = ser.readline() - if line: - print("Received:", line.decode('utf-8', errors='ignore')) \ No newline at end of file + line = ser.readline().decode('utf-8', errors='ignore').strip() + if not line: + continue + + match = json_pattern.search(line) + if match: + try: + data = json.loads(match.group()) + print("Received JSON:", data) + except json.JSONDecodeError: + pass # ignore lines that aren't valid JSON