-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpstime3.py
44 lines (31 loc) · 919 Bytes
/
gpstime3.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
import os
import sys
import time
import gpsd
import logging
def setgpstime():
logging.warning('Attempting to access GPS time...')
connected=False
while not connected:
try:
gpsd.connect()
connected=True
except:
logging.critical('No GPS connection present. TIME NOT SET.')
time.sleep(0.5)
waitingtime = True
while waitingtime:
try:
packet = gpsd.get_current()
gpstime = packet.get_time()
timestr = str(gpstime)
logging.warning('Setting system time to GPS time...')
logging.warning(timestr)
os.system('sudo date -u --set="%s"' % gpstime)
logging.warning('System time set.')
waitingtime=False
except:
logging.warning('Waiting for GPS')
time.sleep(1)
if __name__ == '__main__':
setgpstime()