Browse Source

more robust gw info - log fix

master
Tobias Brunner 9 months ago
parent
commit
124b3b2d5e
1 changed files with 12 additions and 6 deletions
  1. +12
    -6
      lgt92.py

+ 12
- 6
lgt92.py View File

@ -50,12 +50,15 @@ def on_message_ttn(client, userdata, msg):
# retrieve info about gateway
gtw_id = data["metadata"]["gateways"][0]["gtw_id"]
gtw_info = requests.get("https://www.thethingsnetwork.org/gateway-data/gateway/"+gtw_id).json()
logging.info("received via gw %s, %s, owned by %s",
data["metadata"]["gateways"][0]["gtw_id"],
gtw_info[gtw_id]["description"],
gtw_info[gtw_id]["owner"],
)
try:
gtw_info = requests.get("https://www.thethingsnetwork.org/gateway-data/gateway/"+gtw_id).json()
logging.info("received via gw %s, %s, owned by %s",
data["metadata"]["gateways"][0]["gtw_id"],
gtw_info[gtw_id]["description"],
gtw_info[gtw_id]["owner"],
)
except:
logging.info("received via gw %s", gtw_id)
# max is 4 volts, 3 volts is considered empty
batpercent = round((data["payload_fields"]["batV"] - 3) * 100)
@ -63,7 +66,9 @@ def on_message_ttn(client, userdata, msg):
if data["payload_fields"]["alarm"]:
print("ALARM button pressed")
got_fix = False
if "latitude" in data["payload_fields"]:
got_fix = True
# transform received data into OwnTracks format
ot_data = json.dumps({
"_type": "location",
@ -103,6 +108,7 @@ def on_message_ttn(client, userdata, msg):
"counter": data["counter"],
"airtime": data["metadata"]["airtime"],
"rssi": data["metadata"]["gateways"][0]["rssi"],
"fix": got_fix,
}
}]
)


Loading…
Cancel
Save