Skip to content

Commit

Permalink
[TTN] extract metadata from full TTN payload
Browse files Browse the repository at this point in the history
  • Loading branch information
thiasB committed May 9, 2023
1 parent b13ed5b commit 3df3c62
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions kotori/daq/decoder/tts_ttn.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,19 @@ def decode(payload: str):
if "received_at" in message:
data["timestamp"] = message["received_at"]
data.update(message["uplink_message"]["decoded_payload"])

# TODO: Add more data / metadata.
# This is an implementation from scratch. It can be improved by
# cherry-picking more specific decoding routines from `ttnlogger`.
# https://github.com/mqtt-tools/ttnlogger
if "device_id" in message:
data["device_id"] = message["end_device_ids"]["device_id"]
if "settings" in message:
data["bw"] = message["uplink_message"]["settings"]["data_rate"]["lora"]["bandwidth"] / 1000
data["sf"] = message["uplink_message"]["settings"]["data_rate"]["lora"]["spreading_factor"]
data["freq"] = float(message["uplink_message"]["settings"]["frequency"]) / 1000000.0
if "f_cnt" in message:
data["counter"] = int(message["uplink_message"]["f_cnt"])
if "rx_metadata" in message:
data["gtw_count"] = len(message["uplink_message"]["rx_metadata"])
for in range(0, data["gtw_count"]):
gateway_id = message["uplink_message"]["rx_metadata"][i]["gateway_ids"]["gateway_id"]
data["gw_" + gateway_id + "_rssi"] = message["uplink_message"]["rx_metadata"][i]["rssi"]
data["gw_" + gateway_id + "_snr"] = message["uplink_message"]["rx_metadata"][i]["snr"]

return data

0 comments on commit 3df3c62

Please sign in to comment.