Notices


Reply
Thread Tools
Posts: 94 | Thanked: 40 times | Joined on Jun 2010 @ Germany
#1
As I found no real software for the N900 which allows you to easily find your N900 over the internet I wrote some simple scripts which allow exactly this. I heard that the minigpsd has support for some commercial tracking website but it needs packages which are not on the extras repo and you never know what they do with your data so here is my current concept:
  • geotrack.py: A really simple script which connects the N900 the internet if it is not already connected and sends it's location to the pygeotrack server via a simple http-get-request. At the moment it's completely invisible unless you list the running processes (to hide it if the phone gets stolen), a status bar applet and GUI will follow if the important features are polished
  • The pygeotrack-server: Two simple .php scripts. A upload script which the phone connects to like geoupload.php?lat=XXX&lon=XXX&id=XXX and a kml.php script which provides a kml-file which auto updates itself in Google-Earth. The locations are stored in a mysql table.
  • Low requirement: Everyone can get a php/mysql server for free, even servers like funpic should be enough. Only needs python-conix and python-location on the N900
  • Simple language/code: The client is in python and can be modified within seconds if you know a little python, the server is in php which is also widely known. All scripts together have less then 100 lines of code at the moment

Already done:
  • geotrack.py connects to the internet and sends the location every n seconds
  • php server stores the locations with timestamps into a sql table
  • php server sends out a simple kml displaying only the last location or the last n ones
  • Use custom icons for the location in Google Earth (a bike in the example picture)
  • Using keys to either track multiple devices or to show the location only to specific people. You can give a link with ?key=XXX to person 1 and ?key=YYY to person 2 and only update with key=XXX if you want that person 1 can see you or key=YYY so that person 2 sees you.
  • show speed at the moment of the last location
  • set up a SVN
  • create Google Map on the server

TODO ideas:
  • put the python-script into a debian package
  • add autostart
  • add GUI for configuration
  • status bar support
  • more advanced .kml-files
    • show speed at the moment of the last location
    • show the last points as a track with time-line (already works) and center the view on the latest one (for real time tracking, has problems with centering the view automatically on the latest point, Google Earth always centers the whole track)
  • set up a SVN if others are interested
  • support multiple keys when updating the location
  • create Google Map on the server
  • add setting to only upload when internet connection is available
  • configure the N900 script from the server (e.g. when updating put new settings into the answer from the server, could be used to change update intervall and other things).

Updates get different colors to get them in one look

The project is now located here with a very simple first version: https://garage.maemo.org/projects/pygeotrack/


So, is there any interest in this application? If some people would be interested I'd package it up and set up a svn (or garage page, didn't look into the whole garage thing yet). I'd also be happy if someone wants to work on it together with me (that's where the SVN comes into the game).
Attached Images
 

Last edited by weißelstone; 2010-07-01 at 16:06.
 

The Following 6 Users Say Thank You to weißelstone For This Useful Post:
Posts: 200 | Thanked: 300 times | Joined on Nov 2009 @ The Netherlands
#2
Yeah, I would like this script. I have also made it myself, but I like to how you did it.

My software:

- Python script on n900 connects to my web server (cgi-bin python script) where coordinates are stored in a file.
- Made also a UI webpage in python/html with use of googlemaps which reads this stored file and shows coordinate list and auto-loads googlemap pictures.

It works very well...
 
Posts: 1,378 | Thanked: 1,604 times | Joined on Jun 2010 @ Göteborg, Sweden
#3
"I am here" - it does some of what you describe, except when prompted to by a trigger sms. AFAIK, it is no longer developed or that was the case when I last looked.

http://talk.maemo.org/showthread.php?t=50246
 
Posts: 94 | Thanked: 40 times | Joined on Jun 2010 @ Germany
#4
@digitalviod: In short it is like this:
python script:
Code:
*snip the whole gps and internet stuff*
    if device.fix:
        if device.fix[1] & location.GPS_DEVICE_LATLONG_SET:
            print "lat = %f, long = %f" % device.fix[4:6]
            url= "http://server.de/gps/upload.php?lat=%f&lon=%f&key=XXX" % device.fix[4:6]
            print url
            req = urllib2.Request(url)
            reply = urllib2.urlopen(req)
PHP script stores to SQL:
PHP Code:
<?php
$db
= new mysqli('localhost''root''root''test');
if (
mysqli_connect_errno()) {
    die (
'Konnte keine Verbindung zur Datenbank aufbauen: '.mysqli_connect_error().'('.mysqli_connect_errno().')');
}

$sql='INSERT INTO
    gps(lat, lon, date)
VALUES
    ('
.$_GET['lat'].',
     '
.$_GET['lon'].',
    NOW());'
;
$result $db->query($sql);
if (!
$result) {
    die (
'Etwas stimmte mit dem Query nicht: '.$db->error);
}
?>
kml-php-script:
PHP Code:
<?php
$db
= new mysqli('localhost''root''root''test');
if (
mysqli_connect_errno()) {
    die (
'Konnte keine Verbindung zur Datenbank aufbauen: '.mysqli_connect_error().'('.mysqli_connect_errno().')');
}

$sql="SELECT
    lat,
    lon,
    DATE_FORMAT(date, '%Y-%m-%dT%H:%i:%sZ') as newdate
FROM
    gps
ORDER BY date DESC LIMIT 1"
;
$result $db->query($sql);
if (!
$result) {
    die (
'Etwas stimmte mit dem Query nicht: '.$db->error);
}
$row $result->fetch_assoc();
echo 
'<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
    <name>KmlFile</name>
     <Style id="bike-icon">
      <IconStyle>
        <Icon>
          <href>http://server.de/gps/bike.png</href>
        </Icon>
      </IconStyle>
    </Style>'
;
$sql="SELECT
    lat,
    lon,
    DATE_FORMAT(date, '%Y-%m-%dT%H:%i:%sZ') as newdate
FROM
    gps
ORDER BY date DESC LIMIT 1"
;
$result $db->query($sql);
if (!
$result) {
    die (
'Etwas stimmte mit dem Query nicht: '.$db->error);
}
while (
$row $result->fetch_assoc()) {
echo 
'<Placemark>
    <name>'
.$row['newdate'].'</name>
    <description>Hier wurde die letzte Position gesendet.</description>
    <Point>
      <coordinates>'
.$row['lon'].','.$row['lat'].',0</coordinates>
    </Point>
        <!--<TimeStamp>
        <when>'
.$row['newdate'].'</when>
        </TimeStamp>-->
        <styleUrl>#bike-icon</styleUrl>
  </Placemark>
  '
;
}
echo 
'</Document>
</kml>'
;
?>
The sql query is double because I had other stuff in this file before which I removed and I forgot the second query. The TimeStamp is commented because the timeline was a bit annoying when new data came in. So this script creates a xml-compatible file which is referenced by the following .kml-file on the local-harddrive:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
    <NetworkLink>
      <name>Mein N900</name>
      <visibility>1</visibility>
      <open>1</open>
      <description>N900 On Tour</description>
      <refreshVisibility>0</refreshVisibility>
      <flyToView>1</flyToView>
      <Link>
        <href>http://server.de/gps/lastpos.php?key=XXX</href>
		<refreshMode>onInterval</refreshMode>
		<refreshInterval>30</refreshInterval>
      </Link>
    </NetworkLink>
</kml>
This structure could also be used to display a embedded Google Map on the webserver as they can parse kml files, too. I know the code is messy but my first goal was to get the information from my phone to Google Earth. Outsourcing the SQL functions into include files and a general cleanup will follow.
So you are using python on the server, too. Is this available on many hosters? I'm only used to php on servers and have zero experience with anything else.

@handaxe: I searched for Iamhere but couldn't find any reliable (recent) info at all. Also I don't want it with SMS as you'd need the phone's number and this script will upload the location as soon as it is connected to any internet connection no matter which sim is inserted. It's still mostly a simple project to learn something about python, maemo, php and the kml files
 
fpp's Avatar
Posts: 2,853 | Thanked: 968 times | Joined on Nov 2005
#5
Perhaps instead of connecting all by itself at fixed intervals (which might be troublesome), the python script could be run only each time a network connection is established (through d-bus signal, as in the Desktop Commmnd Execution Widget) ?
__________________
maemo blog
 
Posts: 94 | Thanked: 40 times | Joined on Jun 2010 @ Germany
#6
Originally Posted by fpp View Post
the python script could be run only each time a network connection is established
This was my first attempt. It works great but was not often enough for me (as my phone does only connect every hour or so for emails when on 3G and I want it to work as real time tracking too if desired). This will be a config option when I get to the GUI (tomorrow I hope).
 
Posts: 200 | Thanked: 300 times | Joined on Nov 2009 @ The Netherlands
#7
Originally Posted by weisselstone:

"...
So you are using python on the server, too. Is this available on many hosters? I'm only used to php on servers and have zero experience with anything else."

I have a 24/7 server at home with a fixed IP address so I can do what I want...

I like to know how you automaticly connect to an available internet connection (detect if there is already a connection and if not connect to a available connect and test if this connection works and if not chose another one and so on...).
 
Posts: 9 | Thanked: 8 times | Joined on Dec 2009
#8
'Looks very cool. A suggestion, if I may - perhaps you could add the ability to update via Google Latitude, which would provide an option for those who may not wish to use their own server (Latitude can also maintain location history as well)?
 
Posts: 94 | Thanked: 40 times | Joined on Jun 2010 @ Germany
#9
Originally Posted by digitalvoid View Post
I like to know how you automaticly connect to an available internet connection (detect if there is already a connection and if not connect to a available connect and test if this connection works and if not chose another one and so on...).
I mostly copied the python-conic sample: http://pymaemo.garage.maemo.org/conic.html

Originally Posted by Ayodeji View Post
'A suggestion, if I may - perhaps you could add the ability to update via Google Latitude, which would provide an option for those who may not wish to use their own server (Latitude can also maintain location history as well)?
I never used Latitude but I see that there is a client already in the extras (or testing/devel) repo. If this is easy to implement this may be an option in the future but for know I' like to improve the self-made server. A history is also included (in fact all locations are stored in the mysql table but for now only the last n ones are shown).
 
Posts: 82 | Thanked: 44 times | Joined on Feb 2010
#10
I also created a similar thing, mainly on the server side, that while not having the kml side, allows additional functionality if you have lost your phone, see http://talk.maemo.org/showthread.php?p=627494 and feel free to use http://www.whereismydevice.com if you want to connect your scripts to it to add any of this functionality!

Cheers,

Ben
__________________
http://www.whereismydevice.com - Recover your device if lost/stolen

http://jqueryinreallife.blogspot.com - Comedy jQuery blog

Last edited by benh_n900; 2010-06-30 at 08:26.
 
Reply


 
Forum Jump


All times are GMT. The time now is 08:33.