diff options
author | Gary E. Miller <gem@rellim.com> | 2016-09-12 17:59:49 -0700 |
---|---|---|
committer | Gary E. Miller <gem@rellim.com> | 2016-09-12 18:01:51 -0700 |
commit | 0c855e50648cb0cb31fb953a09f4bd10aa19d67d (patch) | |
tree | c378729b00c17c105a44205739caf3056d8a7abc /contrib/gpsData.py | |
parent | 36781b572b421cbf75051e0faa40ffb48988ecec (diff) | |
download | gpsd-0c855e50648cb0cb31fb953a09f4bd10aa19d67d.tar.gz |
Add a nice gpsd Python client example.
Thanks to "Dan Mandle <dan@mandle.me>"
Diffstat (limited to 'contrib/gpsData.py')
-rwxr-xr-x | contrib/gpsData.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/contrib/gpsData.py b/contrib/gpsData.py new file mode 100755 index 00000000..807a2702 --- /dev/null +++ b/contrib/gpsData.py @@ -0,0 +1,64 @@ +#! /usr/bin/python +# Written by Dan Mandle http://dan.mandle.me September 2012 +# http://www.danmandle.com/blog/getting-gpsd-to-work-with-python/ +# License: GPL 2.0 +import os +from gps import * +from time import * +import time +import threading + +gpsd = None #seting the global variable + +os.system('clear') #clear the terminal (optional) + +class GpsPoller(threading.Thread): + def __init__(self): + threading.Thread.__init__(self) + global gpsd #bring it in scope + gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info + self.current_value = None + self.running = True #setting the thread running to true + + def run(self): + global gpsd + while gpsp.running: + gpsd.next() #this will continue to loop and grab EACH set of gpsd info to clear the buffer + +if __name__ == '__main__': + gpsp = GpsPoller() # create the thread + try: + gpsp.start() # start it up + while True: + #It may take a second or two to get good data + #print gpsd.fix.latitude,', ',gpsd.fix.longitude,' Time: ',gpsd.utc + + os.system('clear') + + print + print ' GPS reading' + print '----------------------------------------' + print 'latitude ' , gpsd.fix.latitude + print 'longitude ' , gpsd.fix.longitude + print 'time utc ' , gpsd.utc,' + ', gpsd.fix.time + print 'altitude (m)' , gpsd.fix.altitude + print 'eps ' , gpsd.fix.eps + print 'epx ' , gpsd.fix.epx + print 'epv ' , gpsd.fix.epv + print 'ept ' , gpsd.fix.ept + print 'speed (m/s) ' , gpsd.fix.speed + print 'climb ' , gpsd.fix.climb + print 'track ' , gpsd.fix.track + print 'mode ' , gpsd.fix.mode + print + print "%s satellites in view:" % len(gpsd.satellites) + for sat in gpsd.satellites: + print " %r" % sat + + time.sleep(5) #set to whatever + + except (KeyboardInterrupt, SystemExit): #when you press ctrl+c + print "\nKilling Thread..." + gpsp.running = False + gpsp.join() # wait for the thread to finish what it's doing + print "Done.\nExiting." |