TRY IT OUT: If you wish to test the front-end interface on your mobile device, click here and tap 'Find' (not 'Enable'). This is handy if you want to check how well your location service is working, and to get raw lat/lon values! Please note: this will not allow you to send the position updates to your computer - this is purely for your testing only.
UPDATE 2: I have enhanced the web interface further so it supports time-outs and the ability to clear the update backlog that is accumulated following a timeout (see new screenshot below). Thank you to Ryan K for additional testing.
Unfortunately there appears to be a bug that is manifest under Linux: if gpsd is run with no clients connected and updates are sent from the phone, the script will lock up when attempting to send updates to gpsd after an arbitrary period of time. In the short term, this can be fixed by connected to gpsd and sending it a command (e.g. the 'watch' instruction). If a client is connected to it (which should be the case in nearly all circumstances) this doesn't seem to happen. This behaviour has not been seen under Windows.
Preliminary tests on Mac OS X are reported to be successful. If installing gpsd via a package manager, be sure to disable auto-startup (via init.d scripts and/or hotplug, etc) otherwise the gpsd instance launched by the Python script will not be able to bind to the normal listener port and you will be left wondering why you're not getting any data (as you'll be connected to the wrong gpsd instance).
UPDATE 1: I have uploaded a new version of the package (new Python and HTML). The new features include:
- asynchronous updates (no more locking up Safari)
- batching of updates (which should solve the Bluetooth problem described below), and
- filtering of duplicate updates (you will see an asterisk * next to the 'Acc' value, as in the screenshot).
Many thanks to 'gabe' for testing! Also, please be aware that the HTTP server opens files from the current working directory of the Python process. If you're seeing 404s then your current directory is probably not the same as where the script is (you can check the current directory when it is printed out upon starting the Python script).
Tapping 'Find' will send your position to gpsd. Tapping 'Enable' will start the one-second timer and continuously repeat the process, thereby streaming your position to the computer.
The Python script launches gpsd and configures it to listen on a pseudo-terminal for NMEA sentences. It also launches the basic HTTP server that sends the above HTML page to Safari on a GET request, and sends the incoming location data (an AJAX POST) as a properly formatted NMEA sentence to the pseduo-terminal.
I have compiled gpsd for Cygwin, so at the command prompt I see:
HTTP Server running...
iPhone - - [27/Jan/2010 12:50:23] "GET / HTTP/1.1" 200 -
iPhone - - [27/Jan/2010 12:50:33] "POST / HTTP/1.1" 200 -
(The latitude and longitude values are not real in this example.)
The Python script tries to emulate the (in-)valid fix flag in the $GPRMC sentence by checking whether the accuracy of the position report from the iPhone is below some threshold (by default it is 100). This can be changed in the Python script on line 290: if (fAcc < 100). If you're not getting any position data from gpsd, remember to check the accuracy of the incoming data.
If you wish to use a custom web server port, simply edit the Python code toward the bottom of the script. Doing so can avoid the need to run Python with administrative privileges (necessary for privileged ports, such as 80).
If you need to compile gpsd under Cygwin, make sure you install gcc, python and automake packages using the Cygwin installer (you may also need libpthread and others - watch the output of the configure script to be sure). Run 'autogen.sh' (the configure script) to generate the Makefiles, then run 'make', and finally 'make install' to finish the job.
A word of caution: Safari's timer does not tick when the phone is locked, so make sure that you temporarily disble your phone's Auto-lock while you run the page. Also, turn down the brightness to conserve battery power if you are operating wirelessly.
Another note: WiFi provides the best performance. If you want to be mobile and don't want to take your access point and power supply with you, then Internet Tethering is the other option. You will need to install a working tethering profile, which will let you connect using the white cable (this gives your phone power as well) or via Bluetooth (great for maximum mobility). The question then becomes: what is the address of the webserver to put into Safari? As iPhones support the Bluetooth PAN profile, they contain and inbuilt DHCP server that hands out addresses to connected clients. Easily enough, you just need to check what IP has been allocated to your computer (in the range 192.168.20.2 and upward). There is one drawback of using tethering though: Safari/the phone spends a long time trying to do the POST, so the update interval is extended to about five seconds. With a bit of extra hackery, position updates could be buffered and sent in a bundle, however this requires any client of gpsd to also buffer whatever data it is geotagging and then align each sample with the incoming gpsd data based on each position report's time value.