Find Your Lost Pre With GPS Tracking

by Eric on June 30, 2009 · 13 comments

in How To,PDA / Smartphones

All info can be found here: GPS Tracking @ Pre Dev Wiki

This little modification will allow you to track your Palm Pre if it ever gets lost or stolen. Just ask this guy what he thinks about GPS tracking on his iPhone.

After implementing this GPS tracking method, your Pre will email you updates with GPS coordinates based on a predefined schedule. The email you receive will contain the Pre’s battery information as well as a Google Maps link of where the GPS coordinates are pointing to.

pre gps track gmail emails

pre gps track gmail emails google maps

To start, you’ll need to have a rooted Pre with SSH access.

Instructions:

  1. Mount the file system with read-write access.
    mount -o remount,rw /
  2. Make a directory for the GPS tracking script we’re about to make.
    mkdir /home/scripts
  3. Add the code below to the beginning of the /etc/event.d/crond to enable the cron daemon at startup.
    start on stopped configure
    stop on runlevel [!2]
    description "crond"
  4. Create a crontab entry and schedule the tracking script to run. NOTE: I’m using nano as the text editor. If you do not have nano, you can install it using the Optware package feed, or just use vi as the editor.
    mkdir -p /etc/cron/crontabs
    nano -w /etc/cron/crontabs/root

    Add the following to /etc/cron/crontabs/root:

    */5 * * * * /home/scripts/track.sh

    The */5 means the script will run every time the number of minutes is divisible by 5. E.g. at 5, 10, 15 minutes, etc. Increase the denominator for less frequent updates.

  5. Finally, create the track.sh script in the /home/scripts directory created in step 2.
    nano -w /home/scripts/track.sh

    Copy/paste the code below, but be sure to edit line 2 to include your email address

    #!/bin/sh
    DEST=YOUR_USERID@DOMAIN.com
    
    pos=$(luna-send -n 2 palm://com.palm.location/startTracking '{"appId": "ILovePalm", "subscribe": true}' 2>&1 | tail -1 | cut -d, -f4,5,8 | sed -r 's/[^-\.0-9,]//g')
    
    lat=$(echo $pos | cut -d, -f1)
    lon=$(echo $pos | cut -d, -f2)
    spd=$(echo $pos | cut -d, -f3)
    bat=$(grep BATTERY: /var/log/messages | tail -1 | awk '{print $8}' | sed 's/%,//')
    
    now=$(date)
    
    # Enable this below if you want to keep logs - not sure where to write them /var/home/root not the best place.
    # echo $now,$lat,$lon,$spd,$bat >>mygpsdata.log
    
    #Build a message variable for all the data to be logged.
    msg=$(echo $now,$lat,$lon,$spd,$bat )
    
    #Build message content to be sent
    msg2=$(echo $now Speed:$spd  Battery Level:$bat  URL http://maps.google.com/maps?q=$lat%2C$lon)
    
    ret1=$(luna-send -n 1 palm://com.palm.messaging/sendMessageFromCompose '{"recipientJSONArray": [{"value": "'${DEST}'", "contactDisplay": "'${DEST}'", "prefix": "to$A", "identifier": "palm_anon_element_8"}], "messageText": "'"$msg2"'"}' 2>&1)
    
    exit
  6. Reboot your phone to start the cron daemon and you’re finished. You should now see emails coming into your inbox with the GPS coordinates of your Pre. I just archive the emails in Gmail to keep my inbox from becoming cluttered.

Here’s the tracking in action:

pre gps track google maps


{ 1 trackback }

Geek Squeaks’ of the Week (#17) « What’s On My PC
07.01.09 at 12:27 pm

{ 12 comments… read them below or add one }

1 corq 07.02.09 at 12:23 pm

Just as a caveat – copy/pasting this in nano or vi, even via ssh in the terminal, “broke” (wrapped) some of the longer lines in this. Once I cleaned up the line breaks this worked nicely.

2 Eric 07.05.09 at 7:37 pm

Hey, i’ve been trying to get crond to work while the phone is asleep (eg the screen is off but it’s really on). this method nor using the ipkg-opt crond seams to allow a process to while the screen is off.

Update http://predev.wikidot.com/crond if you know how to fix this :)

3 Eric 07.06.09 at 8:38 am

corq – Thanks for pointing that out. That’s the same problem I had at one point. The solution is to use “nano -w”; I’ve updated the post with this info.

Eric – Unfortunately, it seems like that’s just the way things are. When the phone is charging, the emails get sent every 5 minutes. When it’s not, cron seems to run the job sporadically. The variance opens up to 5-20 minutes.

4 mike 07.10.09 at 3:51 am

I added a bit more to this script to allow someone to send a text message to my pre with a “secret” word. when my pre gets the text message, it replies back to the sending phone with the gps coordinates embedded in a googlemap URL. you still get emailed the google URL every 5 minutes as well.

if anyone’s interested, send me an email!
Mike Kuriger

5 mike 07.10.09 at 3:53 am

as for cron, it seems the entire OS is put to sleep when the power management daemon shuts the screen off. I found that if I kill powerd (initctl stop powerd) cron works great. However, you can’t shut the screen off anymore. Hopefully someone comes up with a way for cron (or some other job scheduler) to wake the pre up in the background

6 Jim 07.14.09 at 5:13 pm

Mike, don’t see your email, but would be interested in the secret txt!

7 Jim 07.14.09 at 5:14 pm

my email is my post name AT houseofraymond dot com

8 aselvan 08.07.09 at 8:40 am

Since PalmPre battery is pretty bad, I have GPS off to save battery. In order for this to work I have added calls to turn on GPS before and after this code.


# make sure gps is on
luna-send -n 1 palm://com.palm.location/setUseGps {\"useGps\":\"true\"} >/dev/null
# wait for 1min so gps gets a lock
sleep 60

# the rest of the code from the top of this article.

# disable gps
luna-send -n 1 palm://com.palm.location/setUseGps {\"useGps\":\"false\"} >/dev/null

Did anyone figure out how to use mail API instead of text message to send mail?.

9 aselvan 08.07.09 at 8:43 am

The stderr redirection part got cut off in my post, here is the full command including it

luna-send -n 1 palm://com.palm.location/setUseGps {\”useGps\”:\”true\”} >/dev/null 2>&1
luna-send -n 1 palm://com.palm.location/setUseGps {\”useGps\”:\”false\”} >/dev/null 2>&1

10 Nnyan 08.12.09 at 4:00 pm

Mike,

I would also like to get your mod to this. If possible could you include aselvan’s code to turn on the GPS?

email: my name at hotmail dot com

Thank you!

11 Rocky 08.13.09 at 5:01 pm

Hey Mike,
I would love to have that feature for my Pre as well. I dont know about anyone else but it would give me a great sense of security.

email: lerocky AT yahoo dot com

12 Rocky 08.17.09 at 1:35 am

I followed every instruction to the letter, and been going over it for the past 2 days. Still not working >.<

email = lerocky at yahoo dot com

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Comment moderation is enabled. Your comment may take some time to appear.

Previous post:

Next post: