You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.2 KiB

import RYLR896Py
from _thread import *
import threading
import json
import requests
# 1. Setup serial connection
lora = RYLR896Py.RYLR896("/dev/ttyS0", 115200)
lora.SetRFParamsLessThan3KM()
def dataHandler(data):
# Split data on '|' separator character
dataSplit = data["message"].split("|")
dataToSend = {}
dataToSend["drone_id"] = dataSplit[0]
dataToSend["GPRMC"] = dataSplit[1]
dataToSend["sensorReadings"] = {}
for sensorReading in dataSplit[2:]:
name = sensorReading.split("=")[0]
reading = sensorReading.split("=")[1]
dataToSend["sensorReadings"][name] = reading
jsonData = json.dumps(dataToSend)
url = 'http://192.168.100.11:3000/logs'
req = requests.post(url, json = dataToSend)
print(req.text)
# 2. Listen for data
while True:
data = lora.Receive()
if data is not None:
# On data:
# a. Check if valid
# b. Parse into object
# c. Prepare server request
# d. Send request to REST API
start_new_thread(dataHandler, (data,))
# Split packet and structure into a JSON object
# Send Post request to REST API with JSON object in request body