-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGPS_Test.py
59 lines (43 loc) · 1.13 KB
/
GPS_Test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from pprint import pprint
import gpsd
import pendulum
def gps_str_to_local_human(gps_str):
"""
Convert raw GPS string to local time and humanize it
"""
dt = pendulum.parse(gps_str)
dt = dt.in_timezone(pendulum.now().timezone_name)
return dt
def dt_format(dt, military=True):
"""
Format dt object to use DayName, 23:01:01 PM
"""
if military:
return dt.format('dddd, HH:mm:ss')
else:
return dt.format('dddd, hh:mm:ss A')
try:
# Connect to the local gpsd
gpsd.connect()
except UserWarning as e:
print(e)
# Get gps position
packet = gpsd.get_current()
# See the inline docs for GpsResponse for the available data
pprint(vars(packet), indent=4)
dt = gps_str_to_local_human(packet.time)
dt_formated = dt_format(dt, military=False)
# print("Current time: {}".format(dt_formated))
# print("Latitude: {}".format(packet.lat))
# print("Longitude: {}".format(packet.lon))
# print("Altitude: {}".format(packet.alt))
# 'alt': float,
# 'climb': float,
# 'hspeed': float,
# 'lat': float,
# 'lon': float,
# 'mode': int,
# 'sats': int,
# 'sats_valid': int,
# 'time': str,
# 'track': float