Fix lora receiver
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user