Thursday, December 27, 2012

GPSD

Ok now we get to some of the fun stuff. Getting info from the GPS in Linux.

As I mentioned in the previous post the GPS will transmit information on a USB port to be picked up by 'something' that can then take the data, translate it, and do something with it.

You could just use a program to read direct from the USB port and then translate the data yourself.

OR

You could use something to handle all the complicated stuff and just give you the data that you can easily get to from your program.

And that something is GPSD (GPS Daemon). It's a Linux daemon that runs in the background, finds your GPS, does all the configuration stuff, then transmits the formatted data over a TCPIP port (2947).

And it comes with a pre-build library for a number of programming languages so you can just call functions from your program to get the data you need.

The GPSD website can be found here so you can read up a bit more about what it does and how it works.

First things first, we need to install it onto our VBOX, we'll need to do this on the RasPi when we get it.

So, fire up your Debian wheezy Virtual Machine and login. Start up a root terminal.

To install what we need at the prompt enter
sudo apt-get install gpsd gpsd-clients
 The just follow the prompts.

This will install the gpsd daemon and some gpsd client programs as well, useful for testing and diagnosing any problems. It should also install the python-gpsd library we need to.

All being well gpsd should now be running and connected to your GPS.

You can check if gpsd is running by typing

ps -ef | grep gpsd
That should list a line something like

gpsd -F /var/run/gpsd.sock
If that's the case then gpsd is up and running. If not then re-boot the virtual machine and check again. If it's still not started then run through the troubleshooting guide on the gpsd website.

Assuming gpsd is now running lets see if it can see the gps ok. This is where the gps clients that we installed come in handy.

In the root terminal type
cgps
This will start a programme that will connect to the gps and start displaying information on screen that has been fed back from the gps. See below.



If your getting data through then this confirms gpsd is up and running, connected to your GPS and sending out data ok.

Again, if not then refer back to the gpsd troubleshooting guide.

NOTE:

I have had a few occasions when gpsd has stopped working. It can usually be fixed by either disconnecting the GPS 'prolific' device from the Virtual Machine (right click on USB Icon and deselect the prolific device), then add it back again.

Failing that kill the gpsd daemon and restart it again
sudo killall gpsd
sudo gpsd -F /var/run/gpsd.sock /dev/ttyUSB0
Assuming your GPS is connected to ttyUSB0

NOTE 2:

Although we haven't setup the GPS on the RasPi yet, and it's exactly the same process as above, there seems to be a known bug where the gpsd daemon doesn't always pick up the GPS automatically at boot. You can just do a kill and restart as above to get it going again.

So now we have a working GPS that can be accessed via gpsd. Next step (and post), lets put some code together in python to grab the data and do something with it.

No comments:

Post a Comment