47 lines
1.7 KiB
Python
47 lines
1.7 KiB
Python
|
import logging
|
||
|
|
||
|
import requests
|
||
|
|
||
|
_logger = logging.getLogger('MAIN').getChild('DAWARICH')
|
||
|
|
||
|
|
||
|
def send_to_dawarich(entity_id, timestamp, latitude, longitude, gps_accuracy, vertical_accuracy, altitude, battery, speed_kph, config_data):
|
||
|
url = f'{config_data["dawarich"]["host"]}/api/v1/overland/batches?api_key={config_data["dawarich"]["api_key"]}'
|
||
|
data = {
|
||
|
"locations": [
|
||
|
{
|
||
|
"type": "Feature",
|
||
|
"geometry": {
|
||
|
"type": "Point",
|
||
|
"coordinates": [
|
||
|
longitude,
|
||
|
latitude
|
||
|
]
|
||
|
},
|
||
|
"properties": {
|
||
|
"api_key": config_data['dawarich']['api_key'],
|
||
|
"timestamp": timestamp.isoformat(),
|
||
|
"altitude": altitude,
|
||
|
"speed": speed_kph,
|
||
|
"horizontal_accuracy": gps_accuracy,
|
||
|
"vertical_accuracy": vertical_accuracy,
|
||
|
"motion": [],
|
||
|
"pauses": False,
|
||
|
"activity": "",
|
||
|
"desired_accuracy": 0,
|
||
|
"deferred": 0,
|
||
|
"significant_change": "unknown",
|
||
|
"locations_in_payload": 1,
|
||
|
"device_id": entity_id,
|
||
|
"wifi": "unknown",
|
||
|
"battery_state": "unknown",
|
||
|
"battery_level": battery
|
||
|
}
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
headers = {'Content-Type': 'application/json'}
|
||
|
response = requests.post(url, json=data, headers=headers)
|
||
|
if response.status_code != 201:
|
||
|
_logger.error(f'Failed to send data to dawarich for entity "{entity_id}": {response.status_code} -- {response.text}')
|