Using your GPS

Now that you're GPS is up and running, and gpsd is playing nice with it, it's time to do something with the data!

The easiest way to get started is using the WebIDE and a bit of python code to access gpsd.

Create a new file in the WebIDE, and then add and run the following code:
import gps

# Listen on port 2947 (gpsd) of localhost
session = gps.gps("localhost", "2947")
session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)

while True:
    try:
    	report = session.next()
		# Wait for a 'TPV' report and display the current time
		# To see all report data, uncomment the line below
		# print report
        if report['class'] == 'TPV':
            if hasattr(report, 'time'):
                print report.time
    except KeyError:
		pass
    except KeyboardInterrupt:
		quit()
    except StopIteration:
		session = None
		print "GPSD has terminated"
This should give you something similar to the following (with an update every second or so):
Looking for position data rather than just the timestamp? Essentially, all you have to do is parse the 'report' data following the example above.

To see what data is available, you can uncomment the 'print report' line, and then just look at the different values and class names and pick and choose whatever you want.

For example, you could use the following code to get the current speed using the TPV class:
		if report['class'] == 'TPV':
			if hasattr(report, 'speed'):
				print report.speed * gps.MPS_TO_KPH
That's it! It's pretty painless, and now it's up to you to figure out what you want to do with you latitude, longitude, date and time, speed, altitude, etc.!
Last updated on 2015-05-04 at 04.27.56 PM Published on 2013-01-24 at 11.34.25 AM