Fix lora receiver

This commit is contained in:
2025-12-27 14:45:21 +01:00
parent 495868a170
commit 8ea7f33fbd

View File

@@ -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'))
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