Created
July 16, 2019 11:55
-
-
Save fradaloisio/64bc3a3e0a9252a6fe5a04aa45a4abf0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from gps3 import agps3 | |
import time | |
import dateutil.parser as dp | |
import requests | |
#host = '192.168.1.15' | |
host = '127.0.0.1' | |
s = 30 | |
traccar_server = "https://XXXXXXX/traccar/" | |
traccar_id_device = 11111 | |
def isnumeric(obj): | |
try: | |
obj + 0 | |
return True | |
except TypeError: | |
return False | |
gps_socket = agps3.GPSDSocket() | |
data_stream = agps3.DataStream() | |
gps_socket.connect(host=host) | |
gps_socket.watch() | |
for new_data in gps_socket: | |
if new_data: | |
data_stream.unpack(new_data) | |
if isnumeric(data_stream.alt) and isnumeric(data_stream.lat) and isnumeric(data_stream.lon) and isnumeric(data_stream.speed): | |
payload = {} | |
payload['id'] = traccar_id_device | |
payload['timestamp'] = dp.parse(data_stream.time).strftime('%s') | |
payload['lat'] =data_stream.lat | |
payload['lon'] =data_stream.lon | |
payload['speed'] =data_stream.speed | |
payload['altitude'] =data_stream.alt | |
print payload | |
r = requests.post(traccar_server, data=payload) | |
print r.status_code | |
print r.text | |
time.sleep(s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment