Skip to content

Commit

Permalink
Merge remote-tracking branch
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyantosch committed Jun 25, 2023
2 parents 1917f79 + 9cffde5 commit 289c1b6
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions webApp/Backend/sensor/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,27 @@ def on_message(client, userdata, msg):

# Parsing the payload message for the data we want
def process_message(msg):
msg = [{-2: "gps", 6: 6, 3: "1234.5678,1234.5678"}, {-2: "crash", 6: 1, 4: True}, {-2: "hum", 6: 2, 2: 61}]
# Decode the SenML message
# Might change to SenmlRecord
# Convert SenML data to JSON format
# payload = json.dumps(msg)
doc = SenmlPack('Payload')
doc.add(msg)

json_data = doc.to_json()

# Extract values from the first SenML data object
# Extracts GPS
first_senml_data = json_data[0]
value = first_senml_data[3]
sensor = first_senml_data[-2]
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

print("Current Time:", current_time)
print("GPS Value:", value)
print("Sensor Type:", sensor)

# Print the decoded SenML message
print("=============================================")
print(doc.to_json())


Expand All @@ -118,6 +129,11 @@ def process_message(msg):
file.write("MQTT started execution....")
file.close()

# client = mqtt.Client()
# client.on_connect = on_connect
# client.on_message = on_message


client.username_pw_set(USERNAME, API_KEY)
client.connect(TTN_MQTT_SERVER, 80, 60)

Expand Down

0 comments on commit 289c1b6

Please sign in to comment.