How to track your node's movements with GPS and OML2¶
1. Prerequisites¶
- Make sure that you understand how OMF works from a user's point of view.
- Make sure that you have completed and understood the basic "Hello World" tutorial.
2. Goal¶
- If your nodes are mobile and out in the field, you may want to equip them with a GPS receiver to get accurate location and timestamp readings in an OML database. You can use this data to plot live maps, trigger actions at certain locations and use the atomic clock timestamps for synchronisation of data collected from various nodes.
- This tutorial shows you:
- how to write an OMF Application Definition for the GPS client
- how to use it within your Experiment Description
3. Scenario¶
- In this scenario, one of the nodes is running the gpsd server that fetches location data from a compatible GPS device attached via USB, serial port or bluetooth. See here for a list of supported GPS receivers. A small GPSlogger application is started on the node by OMF, collects GPS data from gpsd over a socket and feeds it into a OML2 server instance.
4. Building & testing the GPSlogger binary in Ubuntu¶
- make sure you have the OMF/OML repository in your
/etc/apt/sources.list. You can find instructions on how to add this in the OMF or OML installation guides on this site. - install some dependencies:
sudo apt-get install libgps-dev liboml2-dev liboml2-0 libgps19 gcc git-core - check out OML Applications by running
git clone git://git.mytestbed.net/oml-apps.gitandcd oml-apps/gpslogger - build the application with
gcc -o gpslogger gpslogger.c -loml2 -lgps - copy the
gpsloggerfile to the node - on the node, run
sudo apt-get install liboml2-0 libgps19 gpsd - connect your GPS receiver to the node. USB receivers should be detected automatically. For serial port receivers, run
dpkg-reconfigure gpsdand enter the serial port device (e.g. "/dev/ttyS0"). Please see the gpsd website to read on how to configure Bluetooth receivers. - now run
./gpslogger -von the node. If your GPS receiver has been detected and has obtained a satellite fix, you should see some lines being printed:
# OML Client V2.4.0 Copyright (c)2007-2010, NICTA # OML Protocol V2 lat="43.691610" lon="7.248393" ele="nan" fix="2d" ts="2009-11-27T13:16:18Z" lat="43.691435" lon="7.247865" ele="nan" fix="2d" ts="2009-11-27T13:16:22Z" lat="43.691388" lon="7.247720" ele="nan" fix="2d" ts="2009-11-27T13:16:23Z" lat="43.691338" lon="7.247573" ele="nan" fix="2d" ts="2009-11-27T13:16:24Z" lat="43.691288" lon="7.247408" ele="nan" fix="2d" ts="2009-11-27T13:16:25Z"
- add the gpslogger binary to a tar archive:
tar cf gpslogger.tar gpsloggerand place it in the same folder where you will run your experiment from, so that the EC can find it and serve it to the nodes. - alternatively, you can upload the tarball to a webserver and specify the full URL instead of just the filename in your experiment (appPackage parameter).
5. The Application Definition & Experiment for the GPSlogger Application¶
- To understand on how to define an application and install it on your nodes as part of the experiment, please see BasicTutorialStage3-5-3
- Here's the application definition in an experiment (gpslogger.rb):
1 defProperty('node', "omf.nicta.node8", "ID of a node")
2
3 defApplication('gpslogger', 'gps') do |app|
4
5 app.path = "/gpslogger"
6 app.appPackage = "gpslogger.tar"
7 app.version(1, 0, 0)
8 app.shortDescription = "GPS logger"
9 app.description = "Retrieves GPS fix data from gpsd and feeds it into OML."
10
11 app.defMeasurement('gps_data') do |mp|
12 mp.defMetric('lat',:float)
13 mp.defMetric('lon',:float)
14 mp.defMetric('ele',:float)
15 mp.defMetric('fix',:string)
16 mp.defMetric('time',:string)
17 end
18
19 end
20
21 defGroup('Actor', property.node) {|n|
22 n.addApplication("gpslogger") {|app|
23 app.measure('gps_data', :interval => 3)
24 }
25 }
26
27 onEvent(:ALL_UP_AND_INSTALLED) {|node|
28 wait 5
29 allGroups.startApplications
30 wait 10
31 Experiment.done
32 }
6. Running the experiment¶
- run it with
omf-5.3 exec gpslogger.rb
7. The Results¶
The GPS fix data should now be in a sqlite database file on your OML server. See the basic "Hello World" tutorial on how to retrieve the database. The SQL dump of your result database should look like this:
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE _experiment_metadata (key TEXT PRIMARY KEY, value TEXT);
INSERT INTO "_experiment_metadata" VALUES('start_time','1284696934');
CREATE TABLE _senders (name TEXT PRIMARY KEY, id INTEGER UNIQUE);
INSERT INTO "_senders" VALUES('gpslogger',1);
CREATE TABLE GPSlogger_gps_data (oml_sender_id INTEGER, oml_seq INTEGER, oml_ts_client REAL, oml_ts_server REAL, lat REAL, lon REAL, ele REAL, fix TEXT, time TEXT);
INSERT INTO "GPSlogger_gps_data" VALUES(1,1,1.62685999833047,1.627012,-33.8954726457596,151.19676399231,34.8819999694824,'3d','2010-09-17T04:08:57Z');
INSERT INTO "GPSlogger_gps_data" VALUES(1,2,2.23852899670601,2.238653,-33.8954726457596,151.19676399231,34.8819999694824,'3d','2010-09-17T04:08:58Z');
INSERT INTO "GPSlogger_gps_data" VALUES(1,3,3.57356399670243,3.573689,-33.8954726457596,151.19676399231,34.8819999694824,'3d','2010-09-17T04:08:59Z');
INSERT INTO "GPSlogger_gps_data" VALUES(1,4,4.26647099852562,4.26659,-33.8954699635506,151.196782827377,33.5249999761581,'3d','2010-09-17T04:09:00Z');
...
Here's a visualisation of some GPS walk data, which was made with external GPS mapping tools: