Browse Source

feat: Parse data into JSON

master
Konstantinos Kamaropoulos 5 years ago
parent
commit
37e929f83c
  1. 22
      main.py

22
main.py

@ -1,6 +1,7 @@
import RYLR896Py import RYLR896Py
from _thread import * from _thread import *
import threading import threading
import json
# 1. Setup serial connection # 1. Setup serial connection
lora = RYLR896Py.RYLR896("/dev/ttyS0", 115200) lora = RYLR896Py.RYLR896("/dev/ttyS0", 115200)
@ -10,13 +11,20 @@ def dataHandler(data):
# Split data on '|' separator character # Split data on '|' separator character
dataSplit = data["message"].split("|") dataSplit = data["message"].split("|")
drone_id = dataSplit[0] dataToSend = {}
gprmc = dataSplit[1]
sensors = dataSplit[2:]
print("drone_id:", drone_id) dataToSend["drone_id"] = dataSplit[0]
print("gprmc:", gprmc) dataToSend["GPRMC"] = dataSplit[1]
print("sensors:", sensors) dataToSend["sensorReadings"] = {}
for sensorReading in dataSplit[2:]:
name = sensorReading.split("=")[0]
reading = sensorReading.split("=")[1]
dataToSend["sensorReadings"][name] = reading
jsonData = json.dumps(dataToSend)
print(jsonData)
# 2. Listen for data # 2. Listen for data
while True: while True:

Loading…
Cancel
Save