Skip to content

Commit

Permalink
decoding the senml payload
Browse files Browse the repository at this point in the history
  • Loading branch information
d-parkin committed Jun 22, 2023
1 parent 975908c commit 332adc3
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions webApp/Backend/sensor/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from .models import Container, SensorData
from django.db import IntegrityError
from django.core.exceptions import ValidationError
from kpn_senml import *




Expand Down Expand Up @@ -78,14 +80,23 @@ def on_message(client, userdata, msg):

# Parsing the payload message for the data we want
def process_message(msg):
payload = json.loads(msg.payload.decode("utf-8"))
# Extract temperature and humidity data
# Decode the SenML message
# Might change to SenmlRecord
payload = SenmlPack(msg)

# Print the decoded SenML message
print(payload.to_json())



# payload = json.loads(msg.payload.decode("utf-8"))
# # Extract temperature and humidity data

sensor = payload['sensor']
value = payload['value'] + payload['unit']
time = payload['time']
# sensor = payload['sensor']
# value = payload['value'] + payload['unit']
# time = payload['time']

return postToDatabase(sensor, value, time)
# return postToDatabase(sensor, value, time)


client = mqtt.Client()
Expand Down

0 comments on commit 332adc3

Please sign in to comment.