Thursday, March 5, 2009

Real-time Navigation on OSX using Motorola i335 Cell Phone

This post explains real-time navigation using the GPS from a Motorola i335 cell phone with Google Earth a Mac OSX laptop. (Note: for the best experience, be sure to read up on using Google Earth in offline mode.)

There are some problems when allowing Google Earth to auto-detect the GPS for tracking. Basically Google Earth auto-probes the serial devices which it thinks might be a GPS; this is problematic in that it can sometimes select the wrong device. For example, in this case Google Earth is auto-selecting the BlueTooth dial-up adapter of my phone instead of using the USB serial connection. Since I have not found a way to force Google Earth to use a specific device, I came up with another method of getting the real-time GPS information into Google Earth.

IMPORTANT: Whatever you do, DON'T use the Google Earth GPS stuff (Tools->GPS); if you've already tried it, reboot your Mac before you proceed with this guide. As I mentioned above, Google Earth trips-up when trying to auto-detect the GPS, and creates a bunch of gpsbabel processes that cannot be killed and which conflict with the steps I provide below.

Connect Motorola i335 phone via usb cable.

Look for the device on the OSX the filesystem:
ls /dev/tty.*

Mine shows up as /dev/tty.usbmodem3d11
(Yes, this is the same serial interface as for the modem. I don't yet know if they are mutually exclusive, meaning either GPS or modem.)

On Moto phone, navigate to the GPS menu. Select Interface. Select NMEA Out, and set to ON. (Important: be sure to set NMEA Out back to 'Off' when you are done; else this will continue to run and considerably impact the phone's battery charge after unplugging the USB cable.)

After switching NMEA Out to "On", you should see a new icon on the phone that represents the GPS running. If you don't see the icon, something might not be functioning properly (see my troubleshooting section below).

Launch GPS babel; Google Earth already includes a version of it, so we'll use it rather than downloading another copy.

In a Terminal window enter:

cd /Applications/Google\ Earth.app/Contents/MacOS/
./gpsbabel -T -i nmea -f /dev/tty.usbmodem3d11 -o kml,points=0,line_color=640000ff,max_position_points=10 -F /tmp/nmea.kml


This continuously reads the real-time NMEA coordinates from the Motorola i335 and writes them to a file in the KML format that Google Earth uses.


Now launch Google Earth. We'll need to create a Network Link by which to get Google Earth to read the coordinates that the i335/gpsbabel are putting out.

From the menu bar, Click Add -> Network Link.
In the Name field, enter Motorola i335 GPS
In the Link field, enter /tmp/nmea.kml
Click on the Refresh tab. Change Time-Based Refresh from Once to Periodically. Check Fly to View on Refresh
Click OK.

Now on the left-hand side of the Google Earth in the Places window you should see a folder titled "Motorola i335 GPS", and under that folder you'll see either "ESTIMATED Position" or "Position", depending on whether or not the GPS has locked onto your coordinates. Make sure that the "Motorola i335 GPS" and "Position" folders have check marks in their boxes; this is needed in order for Google Earth to use the GPS data.

Once the coordinates are found, Google Earth should pan and zoom to your location.

If you've made it this far, congratulations and have fun. I encourage you to read up on using Google Earth in offline mode for the best experience with this setup.

Troubleshooting:

  • Motorola phone not putting out coordinates (is USB connected? NMEA out enabled? Can phone acquire GPS information?)
  • GPSbabel not properly reading from Motorola GPS (are command line options correct?)
  • GPSbabel not properly writing kml (are command line options correct?)
  • Google Earth is not reading the proper kml file (are the file paths correct?)


If you don't see the GPS icon on the phone after enabling NMEA Out, you might want to disconnect the phone and power cycle it, as well as rebooting the Mac and starting this guide again from the beginning.


Don't know if this is possible yet with BlueTooth; there is a serial device that appears under the BT profile, though I haven't spent the time to see if it can output the GPS NMEA information. An additional reason for using the USB cord is that the NMEA out will eat up the battery much faster than when set to off, and when using the USB cord you're effectively using USB power instead of the phone's battery.

DISCLAIMER: Be smart when using this while operating a vehicle. Don't be distracted; if you need to reference the map or use the computer in any way, pull over or have a passenger do it. I'm not responsible for any mishaps.

Cites: Thanks to these guys for the ideas behind this solution, who did something similar on Linux.

2 comments:

Joe Strusz said...

This is the most instructions for this setup I have seen on one page. It seems it would work, however after trying to dump the GPS data into the .kml file I get a "no data found error". I think it is connecting and bonding fine, however just no GPS info. I have NMEA on, yet no go. I will try it over USB cable next, maybe it will work.

Anonymous said...

I tried this but my position seem to be left in the middle of the water and with big exclamation point somewhere off the coast of Africa. Not exactly where I was located. I think my phone isn't writing to the file. After typing in the commands in the terminal, the terminal never seems to finish it's thought if I can put it that way. i didn't give me something back. I don't know If it should or not. I'm not looking for a "good job! kiddo" but something to tell me that gpsbabel is actually writing to the file or to get me back to a command prompt would be good.

I'm thinking this might be something with with my sprint plan. I tried refreshing my position on my phone and it scans but it fails. I don't necessarily have a data plan so I'm wondering if that is it.

However this is the closest thing I've gotten to using the GPS on this thing considering most things I've tried you have to upload a file to the phone and the only way i found is through to be able to do bluetooth and i get that damn "unsupported object" notice. I can never find a stupid sprint content uploader that works.