tralfamadore.com
get unstuck, in time

27 August 2008

Changelog for Locatable 0.3

I'm just about to submit the new version of Locatable. Here are the changes: Locatable
  • More accurate GPS readings. When retrieving a location, wait until the accuracy is within the specified range, or 20 seconds, whichever comes first (i.e. if you set it to "Best", it'll spend the full 20 seconds).
  • New option "Expire after" specifies how stale of a location is allowed to be sent to web sites. Default is 10 minutes. If you set this to "each request", Locatable will pop up every time a web site wants to read your location.
  • New option "Ask permission" defines if and how many times you'll be prompted to allow a site to see your location. Default is to always ask. Set this to "Twice per site" to mimic the behaviour of iPhone native apps.
Relocatable
  • Relocatable is now a daemon process. You can control how often and how fast it runs by editing /System/Library/LaunchDaemons/com.tralfamadore.locatable.plist.
  • You can also run it from the command line (it now lives in /usr/libexec/relocatable), which gives you the following options:
~ root# /usr/libexec/relocatable/Relocatable -h
Usage: Relocatable [-v] [-t SECONDS] [-d SECONDS] [-e CMD]
-d SECONDS      run as a daemon, delay specified seconds between fixes
-e CMD          execute given program (with args) after each location fix,
                 can include @lat@, @long@, and @hacc@ tokens
-t SECONDS      spend specified seconds waiting for a fix, default 30
-v              turn on verbose logging
Let me know if you encounter any issues. Update (30 Aug 08): A few people had questions about getting the command execution piece to work. Here's an example — the important bit is to wrap the whole command in single quotes, otherwise the shell gets confused. First, if Relocatable is already running as a daemon (it will be by default), you need to stop it:
~ root# launchctl unload /System/Library/LaunchDaemons/com.tralfamadore.locatable.plist
Once that's done, you can run Relocatable as a one-off from the command line:
~ root# /usr/libexec/relocatable/Relocatable -v \
> -e 'curl "http://my.site.com/savepos.pl?lat=@lat@&long=@long@&acc=@hacc@"'
Opened LBS database for read...
Started updates...
newLocation: <+51.xxxxxxxxx, -0.xxxxxxxx> +/- 93.21m @ 2008-08-30 13:17:44 +0100
newLocation: <+51.xxxxxxxxx, -0.xxxxxxxx> +/- 93.21m @ 2008-08-30 13:18:29 +0100
Stopped updates
Opened LBS database for write...
* About to connect() to my.site.com port 80 (#0)
*   Trying xxx.xxx.xxx.xxx... connected
* Connected to my.site.com (xxx.xxx.xxx.xxx) port 80 (#0)
> GET /savepos.pl?lat=51.xxxxxxxxxx&lng=-0.xxxxxxxxxxxx&acc=93.21 HTTP/1.1
> User-Agent: curl/7.17.1 (arm-apple-darwin9) libcurl/7.17.1 OpenSSL/0.9.8g zlib/1.2.3
Note the use of the single quotes (to bracket the command passed to Relocatable) and double quotes (to bracket the URL, so it can contain characters that would otherwise confuse the shell, like the ampersand). The same rules regarding quoting apply to editing the daemon plist. Once you're happy with your settings and have edited the plist to your satisfaction, remember to start it back up:
~ root# launchctl load /System/Library/LaunchDaemons/com.tralfamadore.locatable.plist

Labels: , , , ,

37 Comments:

Blogger Evan said...

Hi

I am unable to get the -e option work with Relocatable. Are you able to provide a LaunchDaemon usage example including arguments?

August 30, 2008 5:02 AM  
Blogger Wesley said...

I added an example to the post. It's all about quoting your arguments.

August 30, 2008 1:44 PM  
Anonymous Anonymous said...

I'm trying to use the relocatable launchdaemon to execute a curl command. At the moment I have:
[string]-e[/string]
[string]'curl "http://example.com/add.php?lat=@lat@&long=@long@"'[/string]

nb: I am using square brackets because blogger doesn't permit angle brackets. I have angle brackets in the plist.

I can see via top that Relocatable is running and has a small CPU time measurement, which is increasing each delay period. If I unload the plist, this instance is removed from top. Additionally it terminates locationd. From my weblogs, there's no attempt to load add.php off my site when operating the plist version. I have set permissions on the plist to 744. Any other permissions aborts its loading because of dubious permissions.

Executing /usr/libexec/relocatable/Relocatable -d 30 -t 10 -e 'curl "http://example.com/add.php?lat=@lat@&long=@long@"' -v works flawlessly. If the launchd version has been previously loaded, no prompt is given for access to location information.

So, at the moment: plist doesn't invoke Relocatable the way I thought it would, but running it in a terminal works great.

Any thoughts on how to get the auto one to curl properly?

August 31, 2008 2:23 PM  
Anonymous Anonymous said...

I am the anonymous commentor above. I removed the single quotation marks around the curl "URL" command and it's now functional. The single quotation is required when executing it once-off, but not inside the plist.

August 31, 2008 3:39 PM  
Blogger Martinez said...

I succesfull used your instructions to post a google maps links on ur own twitter site.

I created a file name /bin/tweet with the following contents

#! /bin/sh
curl --basic --user user:password --data status="`/usr/libexec/relocatableRelocatable -t 15 -e 'date && echo mijn locatie http://maps.google.com/maps?q=@lat@@long@'`" http://twitter.com/statuses/update.xml

(only 2 lines). Please change user and password with ur twitter user/passwd

Be sure the script (named Tweet) runs as a daemon.

Martijn

September 1, 2008 11:13 PM  
Blogger mayson14 said...

ive edited com.tralfamadore.locatable.plist
to use the -e argument to pass lat and long to an aspx application ive created, but the web app is never accessed from the iphone... here is the .plist:

[?xml version="1.0" encoding="UTF-8"?]
[!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"]
[plist version="1.0"]
[dict]
[key]KeepAlive[/key]
[true/]
[key]Label[/key]
[string]com.tralfamadore.locatable[/string]
[key]Nice[/key]
[integer]20[/integer]
[key]ProgramArguments[/key]
[array]
[string]/usr/libexec/relocatable/Relocatable[/string]
[string]-d[/string]
[string]30[/string]
[string]-t[/string]
[string]30[/string]
[string]-e[/string]
[string] curl "http://www.myserver.com/storegps.aspx?lat=@lat@&long=@long@"[/string]
[/array]
[key]RunAtLoad[/key]
[true/]
[/dict]
[/plist]

replaced angled brackets for post.. any help would be much appreciated.

September 9, 2008 10:44 AM  
Blogger mayson14 said...

Re: Post Above- I woke up with a server full of entries.. Guess it works!

September 9, 2008 6:10 PM  
Anonymous Anonymous said...

Hi everybody!

I had the same problem with the ' ... but also with the & !
The launchctl doesn't load a file which contains & in it!
Do you have the same problem?

So now my curl seems to be called every XX minutes. However sometimes the curl process seems to be stucked! When I do a ps I see it but it never ends.

Does anybody have the same problem?
Franck

September 28, 2008 11:58 AM  
Blogger Wesley said...

@Anonymous above -- the plist is an XML file so presumably you need to escape the & as &amp;.

September 28, 2008 2:17 PM  
Anonymous iTs mE said...

Hey Wesley.

I would like to use Relocatable and Twitter the way that "martinez" mentioned.

But Relocatable does not work for me. When trying to stop the Daemon via Terminal i get the message "Error unloading com.tralfamadore.locatable"

By trying to lauch Relocatable i get: "Socket is not connected".

Is it possible that you msg me via ICQ on this? My Number is 244382874. I think there is a litte mistake i can`t find on my own. Thx a lot in advance.

excuse my bad english...i am german.

September 30, 2008 6:55 PM  
Anonymous selfix said...

Cheers Wesley!

Thanks for sharing Relocatable with the world. It was the best hello-world like application for me. I guess one of those things that actually pulled me into iPhone development.

I had one quirk though: when trying binary version of Relocatable from .deb: I'd get an error:
246110287.734,CLClientHandleDaemonDataRegistration: server did not accept client registration 2
Got error #1, no location read

But when I compiled it from sources it worked flawlessly.

I'll probably modify it to fit my needs: run as a deamon and log bicycle tracks to a database.

Thanks again!

October 19, 2008 1:07 PM  
Blogger Wesley said...

@selfix: when you say using it from the .deb, do you mean the version installed with Locatable via the Bigboss repository? I haven't seen any problems so just curious what might be the issue.

October 19, 2008 1:27 PM  
Anonymous selfix said...

The one that came from bigboss yes. I did not try running it as a daemon, but what was strange that when run from command line it didn't prompt me to allow access to gps (and probably did not get it later). The version I compiled (unchanged) worked as expected. Even the file size is the same, but the binary is different. I have firmware 2.0.1 on 3G.

October 19, 2008 3:09 PM  
Blogger Martin Cleaver said...

A different approach than sending updates over the air using CURL is to extract information out of the SqLite database after it has synced.

What a cool little app. Thanks Wesley!

October 22, 2008 12:17 AM  
Blogger Martin Cleaver said...

Further to my comment about syncing later... it looks like it keeps clearing out the database?

I've had the app on all day, but the database looks like it is empty?

localhost:/ mobile$ sqlite3 /private/var/mobile/Library/WebKit/Databases/http_lbs.tralfamadore.com_0/0000000000000001.db

sqlite> .dump
BEGIN TRANSACTION;
CREATE TABLE __WebKitDatabaseInfoTable__ (key TEXT NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT REPLACE,value TEXT NOT NULL ON CONFLICT FAIL);
INSERT INTO "__WebKitDatabaseInfoTable__" VALUES('WebKitDatabaseVersionKey','1.0');
CREATE TABLE location (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, tag TEXT NOT NULL, latitude DECIMAL(30,27) NOT NULL, longitude DECIMAL(30,27) NOT NULL, last_update TIMESTAMP);
DELETE FROM sqlite_sequence;
INSERT INTO "sqlite_sequence" VALUES('preferences',1);
CREATE TABLE preferences (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, domain TEXT, accuracy INTEGER NOT NULL, interval INTEGER NOT NULL, enabled INTEGER NOT NULL DEFAULT 1, ask INTEGER NOT NULL DEFAULT 1);
INSERT INTO "preferences" VALUES(1,NULL,1000,600,1,1);
COMMIT;

I'd have expected more INSERT statements.

Thanks again,
Martin.

October 23, 2008 2:56 AM  
Blogger flashman said...

I've installed Locatable but Relocatable won't run from command line. I've navigated to /usr/libexec/relocatable and I see Relocatable there, but get this error:

-sh: Relocatable: command not found

Nobody else has commented on this so I assume I'm doing something wrong. iPhone has been restarted and I've tried this both with com.tralfamadore.locatable.plist loaded and unloaded.

November 10, 2008 11:18 AM  
Blogger Wesley said...

@flashman -- I'm guessing you need to do "./Relocatable" as the libexec directory is not in the shell's executable PATH.

November 10, 2008 11:40 AM  
Anonymous PacmanII said...

I want to use relocatable to locate my iPhone in the case of lost or if it's been stolen. So I implemented the procedure described above and my iPhone posts it's current location via curl to a script on my webserver every 10 min.

The problem is, that this only works when the iPhone is in use. If I turn it off (not really "off", just standby mode) the position isn't updated anymore until I put it on again. So I have lacks in the tracking log on my webserver of about 2-3 hours if I haven't used it for this time. Does anyone else has that problem? And how to solve it?

November 10, 2008 2:28 PM  
Anonymous PacmanII said...

Just as an addional information: With Insomnia switched "on" relocatable works fine. Seems that the power management of the iPhone turns off the GPS receiver when in standby. Insomnia prohibits this but makes the battery going empty within hours. Maybe this can be changed by implementing a wakeup in locatable. For more information visit the Insomnia website: http://code.google.com/p/iphone-insomnia/

"However if you would like your application to do something periodically a much better approach would be to schedule a wake up, and allow it to sleep in between times, to conserve battery power like so:

NSCalendarDate *nextWake = [[NSCalendarDate calendarDate] dateByAddingYears:0 months:0 days:0 hours:0 minutes:15 seconds:0];
CPSchedulePowerUpAtDate((CFDateRef)nextWake);

Then you need to cancel the suspend power notifications while you are doing your work, so the phone stays on while it is working. If you don't do this then it turns off again 15 seconds later interfering with what you need done. This last part is in the Insomnia source code on this site."

November 12, 2008 7:52 AM  
Blogger Malcolm Hall said...

I get the same error when running as a daemon:

CLClientHandleDaemonDataRegistration: server did not accept client registration 2

January 14, 2009 5:29 AM  
Blogger Wesley said...

@Malcolm -- This might mean that the daemon is already running. Did you do the launchctl unload command as noted at the end of the post?

Also try 'ps ax' and see if Relocatable is in the list.

January 14, 2009 10:25 PM  
Anonymous Anonymous said...

Tip for editing the com.tralfamadore.locatable.plist!

I wanted to POST my data to a secure server. I used -d to post the data and the -k because I have a self signed certificate and wanted to ignore the warning. Here is my code I use:

[string] curl -d "lat=@lat@&long=@long@" "https://www.awesome.com/tracker/" -k[/string]

Note: I have changed the brackets in example.

January 22, 2009 9:00 AM  
Anonymous qrios said...

Hi Wesley,

thnx for Locatable! I use it with my iPhone 1. gen and in replace of find-me from Erica Sadun. It sends the location to my server where my current location will be displayed in GoogleMaps.

January 26, 2009 1:51 PM  
Blogger Malcolm Hall said...

@Wesley - Yep only one instance of the daemon is running. It is a core location error probably because CL isn't designed to be used from a daemon without a UIApplicationMain.

February 2, 2009 8:32 PM  
Blogger Mike said...

Hi Wesley,

Thanks for the great piece of SW. Finally got it up and running. Curious, what other values can you pull out the DB it creates? Time-stamps, Heading, etc? Is there some doc describing the database schema?

Regards,

Mike B.

February 9, 2009 10:00 PM  
Blogger Wesley said...

Hi Mike,

Currently not much being stored:
CREATE TABLE preferences (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, domain TEXT, accuracy INTEGER NOT NULL, interval INTEGER NOT NULL, enabled INTEGER NOT NULL DEFAULT 1, ask INTEGER NOT NULL DEFAULT 1)

CREATE TABLE location (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, tag TEXT NOT NULL, latitude DECIMAL(30,27) NOT NULL, longitude DECIMAL(30,27) NOT NULL, last_update TIMESTAMP)

You can poke around if you install sqlite from Cydia...

% sqlite3
/var/mobile/Library/WebKit/Databases/http_lbs.tralfamadore.com_0/*.db

In the next version I'm going to store altitude, hacc and vacc in the DB as well.

Note that it's only saving the latest reading, though you could mod Relocatable to save more.

February 9, 2009 10:30 PM  
Blogger Wesley said...

@Malcolm -- I'm still baffled by your error. I don't see why it's working for others and not for you. Anyone else hit this error?

February 9, 2009 10:33 PM  
Blogger Mike said...

Thanks for this great app. I am using the command line tool as part of an iPhone lojack that I wrote that will respond to tweets, so I send a twitter message to my phone's private twitter account saying "where are you?" and my phone replies with the google maps link.

I just updated to firmware 2.2.1, re-jailbroke etc, and now when I run Relocatable in the command line, i get "Couldn't open master database, message 'library routine called out of sequence'"

It could just be that something else is messed up from re-jailbreaking, but i was thinking that it had to do with the new firmware. the strange part is that it still ultimately sends the correct response (if i use -v, it gives the error, then the next line is "Started updates..." and everything just works normally after that.

any ideas?

February 12, 2009 6:35 PM  
Blogger Rachel said...

@Mike, I'm also getting "Couldn't open master database, message 'library routine called out of sequence'" on 2.2.1. It seems to do the location finding, but I don't think it's writing to or reading from the database and running the curl command that I'm trying it with.

February 22, 2009 5:28 AM  
Blogger Rachel said...

The curl command is working, I just had a typo. I'm still getting the same database message and I don't think the sqlite database is being updated. But I'm more interested in the web updates so that's okay for now. Thanks for a fun program and for releasing your source! It's been very helpful.

February 23, 2009 3:01 AM  
Blogger Wesley said...

Hi Rachel -- I haven't upgraded to 2.2.1 myself so that may be the issue. Will have to do that and see if I can get around the problem.

February 23, 2009 3:10 AM  
Anonymous Anonymous said...

How can you switch permissions ( "Ask permission") ? I need "never" one in my project.

March 5, 2009 2:11 PM  
Blogger deaconblues said...

Thank you for this, Wesley!

I was wondering, it seems there isn't a token for passing timestamp information, but the timestamps are shown in verbose mode. Is there a way to construct the command using awk or something like that to pass timestamp information in executing a command using -e?

March 14, 2009 5:43 PM  
Blogger Martin Cleaver said...

Running top on my iphone, selecting "o" typing "RSHRD", and putting the phone in landscape mode, shows me that relocatable is taking up 12MB of space.

It ranks in space used not far behind SpringBoard (16M) MobileSafari (15M) MobilePhone (13M) and MobileMail (13M).

Is there a way to reduce Relocatable's memory consumption? For a background app it takes up a great deal of space, and "iphone MemTool" shows my iphone is almost out of working memory.

Relative to the 76.2mb available (see furbo.org /2007/08/21/ what-the-iphone-specs-dont-tell-you/ ), using 12MB is just too much.

Thanks,
Martin

May 9, 2009 2:11 PM  
Anonymous Anonymous said...

Relocatable doesn't seem to be working on my iPhone 3G 3.0. I turned on "Location Sharing" in Locatable, and when I run Relocatable manually (after unloading it), I'm only getting:

iPhone:~/bin root# /usr/libexec/relocatable/Relocatable -v
Opened LBS database for read...
Started updates...


any ideas?

June 29, 2009 4:19 AM  
Blogger Martin Cleaver said...

Ah, thanks. Not working for me in 3.0 either - haven't had a chance to look why.

Cheer, Martin

June 29, 2009 12:32 PM  
Blogger tarrinho said...

here also in 3.0

/usr/libexec/relocatable/Relocatable -v -t 1800
Opened LBS database for read...
Started updates...

July 21, 2009 7:35 PM  

Post a Comment

<< Home

Copyright (C) 2001-2008 Tralfamadore.com