publish to traccar
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Tobias Brunner 2023-06-05 08:43:51 +02:00
parent 8952064147
commit df640403c6
Signed by: tobru
SSH key fingerprint: SHA256:kywVhvCA+MIxL6eBgoQa+BfC/ROJqcfD2bpy1PR6Ebk

View file

@ -18,7 +18,7 @@ DST_MQTT_PASS = os.getenv("DST_MQTT_PASS")
DST_TRACCAR_URL = os.getenv("DST_TRACCAR_URL") DST_TRACCAR_URL = os.getenv("DST_TRACCAR_URL")
PUSHOVER_TOKEN = os.getenv("PUSHOVER_TOKEN") PUSHOVER_TOKEN = os.getenv("PUSHOVER_TOKEN")
PUSHOVER_USER_KEY = os.getenv("PUSHOVER_USER_KEY") PUSHOVER_USER_KEY = os.getenv("PUSHOVER_USER_KEY")
VERSION = "v1.1" VERSION = "v1.2"
OT_TOPIC_PREFIX = "owntracks/things/" OT_TOPIC_PREFIX = "owntracks/things/"
@ -85,16 +85,21 @@ def on_message_ttn(client, userdata, msg):
batt = data["uplink_message"]["decoded_payload"].get("batt", 0) batt = data["uplink_message"]["decoded_payload"].get("batt", 0)
if fix == 1: if fix == 1:
logging.info("got payload with a fix") logging.info("got payload with a fix")
latitude = data["uplink_message"]["decoded_payload"].get("lat", 0.0)
longitude = data["uplink_message"]["decoded_payload"].get("lng", 0.0)
timestamp = data["uplink_message"]["decoded_payload"].get("time", 0)
accuracy = data["uplink_message"]["decoded_payload"].get("acc", 0)
battery = data["uplink_message"]["decoded_payload"].get("batt", 0)
ot_data = json.dumps( ot_data = json.dumps(
{ {
"_type": "location", "_type": "location",
"acc": data["uplink_message"]["decoded_payload"].get("acc", 0), "acc": accuracy,
"lat": data["uplink_message"]["decoded_payload"].get("lat", 0.0), "lat": latitude,
"lon": data["uplink_message"]["decoded_payload"].get("lng", 0.0), "lon": longitude,
"batt": data["uplink_message"]["decoded_payload"].get("batt", 0), "batt": battery,
"t": "p", "t": "p",
"tid": device_id, "tid": device_id,
"tst": data["uplink_message"]["decoded_payload"].get("time", 0), "tst": timestamp,
"conn": "m", "conn": "m",
} }
) )
@ -112,12 +117,16 @@ def on_message_ttn(client, userdata, msg):
check_batt(batt=batt, device_id=device_id) check_batt(batt=batt, device_id=device_id)
# send to traccar # send to traccar
# logging.info("publishing data to traccar") logging.info("publishing data to traccar")
# traccar_url = f"{DST_TRACCAR_URL}/?id={device_id}&lat={latitude}&lon={longitude}&timestamp={timestamp}&hdop={hdop}&altitude={altitude}&speed=0" traccar_url = f"{DST_TRACCAR_URL}/?id={device_id}&lat={latitude}&lon={longitude}&timestamp={timestamp}&accuracy={accuracy}&batt={battery}"
# requests.get(traccar_url) requests.get(traccar_url)
elif sos == 0:
logging.info("got payload with a sos")
push_msg(msg=f"Knopf 5 mal gedrückt - deaktiviert", device_id=device_id)
elif sos == 1: elif sos == 1:
logging.info("got payload with a sos") logging.info("got payload with a sos")
push_msg(msg=f"Knopf 5 mal gedrückt", device_id=device_id) push_msg(msg=f"Knopf 5 mal gedrückt - aktiviert", device_id=device_id)
# TODO publish geo:// URL
elif alarm == 1: elif alarm == 1:
logging.info("got payload with an alarm") logging.info("got payload with an alarm")
else: else: