Yesterday I made a little Raspberry Pi GPS tracker using the same application, gpsd, from a past blog.   The client gpspipe is included in the ‘gpsd-clients’ package on most Linux systems (for Raspbian users: sudo apt-get install gpsd gpsd-clients”).   It is a client that allows you to get the data coming from gpsd and send it to stdout.  Stdout then can be redirected anywhere and cool things can happen.

You can test your setup with:

gpsd -n /dev/ttyUSB0
gpspipe -w -n 30

This will print out 30 lines from gpsd on your screen.

In my version of gpsd, the default statements are JSON messages separated by new lines.  So my immediate goal was to write a bash script that parsed the messages and gave me my location.  Since not all the messages contain longitude and latitude data,  I set gpspipe to get 10 lines of data (with the ‘-n 10’ option) an then I picked out the first instance with “lat” in it.  The ‘-w’ option set the output to be in gpsd native format.

gpsdata=$( gpspipe -w -n 10 |   grep -m 1 lat )
//Looks like:
{
"class": "TPV",
"tag": "MID2",
"device": "/dev/ttyUSB0",
"mode": 2,
"time": "2012-12-30T22:02:12.060Z",
"ept": 0.005,
"lat": 31.2124244,
"lon": -91.52671836,
"epx": 5.31,
"epy": 11.125,
"track": 130,
"speed": 0.128,
"eps": 23.15
}

This set gpsdata to one clean line of JSON formated gps data.  I started the search for a lazy way to cut up the JSON and found a great script for parsing JSON on the command line  (requires: apt-get install spidermonkey-bin) that made the task super easy.  So now:
lat=$( echo "$gpsdata"  | jsawk 'return this.lat' )

I did the same thing for long and then printed a statement with url to google maps.
echo "You are here: $lat, $lon - https://maps.google.com/maps?q=$lat,+$lon"

The entire bash script looks like:
#!/bin/bash
gpsdata=$( gpspipe -w -n 10 |   grep -m 1 lon )
lat=$( echo "$gpsdata"  | jsawk 'return this.lat' )
lon=$( echo "$gpsdata"  | jsawk 'return this.lon' )
echo "You are here: $lat, $lon - https://maps.google.com/maps?q=$lat,+$lon"

And that is all you need to be a professional creeper with a GPS dongle, a Raspberry Pi and a Battery.  If you were really wanting to track your adventures, you can gpspipe as a daemon and write the data to a file with “-d -l -o” and parse the data at a later time.  There are tons of services that you can already connect to with gpsd to log/process/map/share, but gpspipe provides a very easy diy way to do your own geotracking.  My goal is to combine this with my Bluetooth proximity detector.

*I plan on testing it on an old Palm Pre, but I imagine it would work on most rooted Linux based phones since all the libraries should compile on old ARM processors.  Anyone have experience?


Comments

  1. Anthony -

    That’s really neat! I just might have to try something similar! Great job.

    Reply
  2. M (@Dr_Radar) -

    Great stuff. I was looking to do something similar. I have gpsd installed and can use the command “cgpd -s” to see the gps info. I’m looking for a way firstly to log this and secondly to transmit/share the info. Any tips?

    Reply
  3. dr memals -

    the gpsd clients comes with gpxlogger which produces nice clean xml

    Reply
  4. Sean -

    Thanks for the gps ideas. What must be installed for get jsawk to work?

    Reply
  5. [email protected] -

    looks really good… I got an error message on my raspberry pi saying… /bin/jsawk: line 1317: js: command not found … any help to this?

    Reply

Leave a Reply