Las Vegas Trip

I organized a road trip to Las Vegas for a friend’s bachelor party. There were 8 of us in total. We’re all into technology, so we made the road trip a little more interesting for ourselves. We decided to map our location (as well as some other interesting bits of information) using Google Maps.

Our friends and family were able to track our status real-time by visiting a web page. This page had several pieces of information:

  • large map detailing where we were and the path that we have taken so far
  • smaller map, zoomed in, showing our exact location
  • image taken from the USB camera, refreshed periodically
  • comment set by us whenever we had something to say
  • Flash chat application

This was the page: http://www.navjagpal.com/vegas. Unfortunately it isn’t too interesting now because nothing is happening, but you should get the idea.

The awesome details:

Requirements

Hardware

  • Bluetooth GPS
  • Macbook Pro
  • Logitech USB camera
  • Power inverter (to keep the laptop charged

Software

  • wacaw – command line tool that allows us to take pictures using the USB camera
  • gpsd – interface with the bluetooth GPS device (installing through Darwin Ports)
  • home-brew Python script
  • Some very basic HTML and Javascript

Getting the Hardware and Software Setup

wacaw

It took us awhile to find software that would work with a USB camera. We needed a command line tool (or library) that would take pictures using the USB camera. You’d think this would be easy to find, or even built-in to OS X. Once we found this software, the installation was pretty straightforward. Just a download and copy of the binary (wacaw) to wherever you want. The command we ended up using to take pictures was:

$: wacaw –width=640 –height=240 somefile

If that produces an image that works, the camera part is setup.

gpsd

We had to install Darwin Ports on the MacBook. After installing darwin ports, installing gpsd was pretty easy. There is a server/daemon component and a client component. The daemon (gpsd!) obtains information from the GPS device and exposes that information to you.

To get it running with our device, I think we used the command:

gpsd /dev/tty.BT-GPS-33334B-BT-GPSCOM-1

You can test that gpsd is running properly by connecting to port 2947 (the default for gpsd) via telnet, and issuing a gpsd command. ‘o’ will give you a bunch of information.

The Code

We wrote several scripts for this project. All of them very simple. Our primary objective was to not lose any information. One way to lose data would be to grab GPS information, then try to upload that information somewhere all in same script. What happens if network is down or the transfer takes too long? You could be recording more GPS data during the transfer.

GPS Recorder

In an infinite loop, record GPS information every second to a file. This was our “raw GPS” data file. Other scripts were able to grab data from the raw file, but this scripts only job was to write data to that file. Actually, we wrote information to two different files. One file was completely raw information retrieved from gpsd using the ‘o’ command. The other file contained data that was easier to parse. The reason we did this was because we weren’t sure what other useful information was available int the gpsd output, so it was probably a safe plan to record it all in case we wanted to go back and look at it later. This second file had entries that looked like:

{timestamp:1209966962.66, lat:37.421302, lon:-122.083705, speed: 1.559, altitude:1.40}

Wow, that looks like a JSON object, doesn’t it?

GPS Pusher

The pusher’s job was to read the file, and send the JSON-like objects to our web server. I think we sent 1 in every 10 lines. We abstracted the pushing of data by creating our own datastore module, which I’ll talk about a little later. The points we sent to the server were used to create the trail on the map as well as update our current location.

Picture Taker

Pretty much like the GPS recorder, except this script took pictures in an infinite loop. It used the wacaw command to take pictures.

Picture Uploader

The uploader would look for new pictures in a particular directory, upload 1 in every 30 pictures to our web server, and move all the pictures to a new directory. Again, this was in an infinite loop. If we have new pictures, send every 30th picture to the server, move all pictures to a new directory for later use. We didn’t use the datastore for uploading of pictures. Instead, we used ftp via ftplib.

Comment Setter

Simple script that used the datastore to upload a comment:

echo “We are on the road!” | ./set_comment.py

HTML/Javascript

The javascript periodically reads the file containing GPS coordinates and updates the map appropriately.

I can post the code we used if people are interested. Just leave a comment.

Tags:

One Response to “Las Vegas Trip”

  1. orionrush says:

    ooooh – oooooh ME ME! I want to see your code!

    If you do decide to post plz shoot me an email.

    Ive been super excited by wacaw – its a partial solution for os x. Unix has so many apps that do a range of video imaging and capture. This is the only OS X CLI app, aside from isightcapture that Ive found to work on all quicktime enabled devices. Would be happy to know of more. . .

Leave a Reply

You must be logged in to post a comment.