Browse Source

new datastructure

master
Tobias Brunner 2 months ago
parent
commit
43969fa842
  1. 13
      rhf1s001.py

13
rhf1s001.py

@ -28,8 +28,7 @@ def on_log(client, userdata, level, buf):
# The callback for when a PUBLISH message is received from the server.
def on_message_ttn(client, userdata, msg):
data = json.loads(msg.payload)
logging.info("message from ttn received for %s - #%s", data["dev_id"], data["counter"])
logging.info("received via gw %s", data["metadata"]["gateways"][0]["gtw_id"])
logging.info("new data received via gw %s", data["uplink_message"]["rx_metadata"][0]["gateway_ids"]["gateway_id"])
# write to influxdb
logging.info("writing data to influxdb")
@ -41,11 +40,11 @@ def on_message_ttn(client, userdata, msg):
"device": "rhf1s001",
},
"fields": {
"battery": data["payload_fields"]["battery"],
"hum": data["payload_fields"]["hum"],
"temp": data["payload_fields"]["temp"],
"counter": data["counter"],
"rssi": data["metadata"]["gateways"][0]["rssi"],
"battery": data["uplink_message"]["decoded_payload"]["battery"],
"hum": data["uplink_message"]["decoded_payload"]["hum"],
"temp": data["uplink_message"]["decoded_payload"]["temp"],
"counter": data["uplink_message"]["f_cnt"],
"rssi": data["uplink_message"]["rx_metadata"][0]["rssi"],
}
}
]

Loading…
Cancel
Save