Difference between revisions of "Patch webOS GPS Tracking"

From WebOS Internals
Jump to: navigation, search
(This corrects the omissin of the entry in the "root" crontab)
Line 41: Line 41:
  
 
== Installation==
 
== Installation==
1. mkdir -p /home/scripts
+
# mkdir -p /home/scripts
 
+
# Let's say you put the script in /home/scripts/track.sh
2. Let's say you put the script in /home/scripts/track.sh
+
# rootfs_open -w
 
+
# Go [[Crond | here ]] to enable crond.
3. rootfs_open -w
+
# Add the following line to /etc/cron/crontabs/root<pre><nowiki>*/5 * * * * /home/scripts/track.sh</nowiki></pre>
 
+
# Now just send the secret code you set in the script to $YOURNUMBER@messaging.sprintpcs.com (without dollar sign but as a ten digit number with area code prefix)
4: Go [[Crond | here ]] to enable crond.
 
 
 
5. Now just send the secret code you set in the script to $YOURNUMBER@messaging.sprintpcs.com (without dollar sign but as a ten digit number with area code prefix)
 
 
> Ex: 3335554444@messaging.sprintpcs.com where 333 is your area code, and 5554444 the rest of your phone number.
 
> Ex: 3335554444@messaging.sprintpcs.com where 333 is your area code, and 5554444 the rest of your phone number.
 
and it will send $DEST the GPS data for the device.
 
and it will send $DEST the GPS data for the device.

Revision as of 15:24, 13 August 2009

<<- Return to webOS Patches


Here is my super happy awesome tracker script!

Script code

SECRET=make up any secret code here
DEST=put your e-mail address here

track()
{
        export IFS=$'\n'
        for loc in $(luna-send -n 3 palm://com.palm.location/startTracking '{"appId": "ILovePalm", "subscribe": true}' 2>&1); do
                send $(echo $loc|cut -f3- -d,)
        done
}

send()
{
        echo "Sending Message: $1"
        msg=$(echo $1| sed s/\"/\\\\\"/g)
        luna-send -n 1 palm://com.palm.messaging/sendMessageFromCompose '{"recipientJSONArray": [{"value": "'${DEST}'", "contactDisplay": "'${DEST}'", "prefix": "to$A", "identifier": "palm_anon_element_8"}], "messageText": "'"$msg"'"}'
}

checkmsg()
{
        echo ".timeout 30000" > /tmp/trackersql
        cmd='SELECT messageText FROM com_palm_pim_FolderEntry WHERE timeStamp > (strftime("%s000", "now")-600000);'
#       output=$(echo $cmd|sqlite3 /var/luna/data/dbdata/PalmDatabase.db3)
        output=$(echo $cmd|sqlite3 -init /tmp/trackersql /var/luna/data/dbdata/PalmDatabase.db3)
        echo $output|grep $SECRET 2> /dev/null > /dev/null
        status=$?

        if [ $status = 0 ]; then
                track
        fi
}

checkmsg

Installation

  1. mkdir -p /home/scripts
  2. Let's say you put the script in /home/scripts/track.sh
  3. rootfs_open -w
  4. Go here to enable crond.
  5. Add the following line to /etc/cron/crontabs/root
    */5 * * * * /home/scripts/track.sh
  6. Now just send the secret code you set in the script to $YOURNUMBER@messaging.sprintpcs.com (without dollar sign but as a ten digit number with area code prefix)

> Ex: 3335554444@messaging.sprintpcs.com where 333 is your area code, and 5554444 the rest of your phone number. and it will send $DEST the GPS data for the device.

Now, just take the latitude and longitude data and generate the URL. As to the other GPS parameter data available we'll have to investigate to see if Google Maps can take those parameters and how they map to the URL. ~Robi

luna-send -n 1 palm://com.palm.location/getCurrentPosition {}
** Message: serviceResponse Handling: 2, {"errorCode":0,"timestamp":1.245799702311E12,"latitude":37.48660683631897,"longitude":-122.23269581794739,"horizAccuracy":37.947330474853516,"heading":178,"velocity":0.75,"altitude":-13,"vertAccuracy":24}

which means we can transpose some of that to a Google Maps link:

http://maps.google.com/?ie=UTF8&q=37.48660683631897,-122.23269581794739+(Heading:%20178%0DSpeed:%200.75%20mph)

If you know more about the GPS parameters, let us know by updating the page. ~Robi

  • Added heading and speed parameters to the URL. If you hover over the pinpoint on the google map, you can see the information, as well as in the info window if you click on the pinpoint. -xluryan

"If [ll=] is used without a query, then the map is centered at the point but no marker or info window is displayed." To get around this, use q=[Lon,Lat] instead of ll=[Lon,Lat]. I changed the maps link above. -hopspitfire


Troubleshooting Tip: Make sure track.sh has the correct file permissions set. To encompass all possibilities, try 'chmod 755 /home/scripts/track.sh'. You can restrict permissions later if you wish. On Windows it's probably easiest to do this through WinSCP (right click>Properties>Permissions).

Development Ideas

1. Send response as a google maps link that clicked on shows the phones position on a map. 2. Find a way to put a hook into message reception so that messages don't have to be checked with a cron job. Even better if the message could be intercepted before appearing on the phone, it would be a useful way to track a stolen phone. 3. After implementing the script that emails me every 20 minutes, it occured to me that the following would be great:

 3a. The ability to log the entries instead of just sending an email, and maintain a preset number of logged entries (say the last 24 entries).
 3b. Using the original implementation - send a message to the device to have the logged information emailed. This would show a "track" of where the device has been.
 3c. Control of the number of log entries, and the frequency.

Another Simple Method

Why not use this script:

#!/bin/sh

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/%,//')

ret=$(wget -qO- "http://yoursite.com/trackme/$1/requests.php?lat=$lat&lon=$lon&speed=$spd&batt=$bat" | egrep -o '[0-9]+$')
exit $ret

I have a web server setup with //requests.php// taking //lat//, //lon//, //speed//, and //batt// arguments. Then it writes them to a file. Use the data however you want. I have mine plug into a google map and show me the data.

Just set up a cron job to call the script every 20 minutes or so. Hardly effects battery life at all :)

Credit to ddoc for info on how to grab battery status. I would still like to find a more efficient way of grabbing battery level rather than searching through the entire message log. Though for now, it works exactly like it should.

Here's the Method for getting battery status:

Mojo.Service.Request('palm://com.palm.power/com/palm/power/', {method: 'batteryStatusQuery',});

-pEEf

Email a URL to open Google Maps showing location of phone.

Below is a code snippet that will send an email with working URL to open Google Map and show you the location of your phone. The cron job mentioned above is setup to call this script every 20 minutes on my machine...works great. I let GMAIL archive them. If the phone gets stolen, I can find it as long as it has service.

The larger Accuracy is, the further away the coordinates output will be from your actual position.

Added speed & heading to Google URL. Is there any way to have the sent messages not appear in the Text Messaging app, or to use the shell to email the output via mailx? Until I figure out a built-in mail function, you can use an alternative I'm testing that uses a server's mailx command: echo "$msg2" | /opt/bin/ssh -x user@server /bin/mailx $DEST -hopspitfire

#!/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,6,7,8 | sed -r 's/[^-\.0-9,]//g')

lat=$(echo $pos | cut -d, -f1)
lon=$(echo $pos | cut -d, -f2)
acc=$(echo $pos | cut -d, -f3)
dir=$(echo $pos | cut -d, -f4)
spd=$(echo $pos | cut -d, -f5)
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,$acc,$dir,$spd,$bat >>mygpsdata.log

#Build a message variable for all the data to be logged.
msg=$(echo $now,$lat,$lon,$acc,$dir,$spd,$bat )

#Build message content to be sent
msg2=$(echo $now Battery:$bat Accuracy:$acc  "http://maps.google.com/maps?q=$lat%2C$lon+(Heading:%20$dir%0DSpeed:%20$spd)")

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

This has been running every 20 minutes on my phone for the last 4 days, no problem. -dld121