Skip to content
anthonyrowe edited this page Dec 30, 2017 · 37 revisions

The GPS Mapper Service allows your transducer to show up on the OpenChirp public map. You can add the GPS Mapping service to any device and it will monitor the "latitude", "longitude" and/or "gps" transducers for your device and update its position accordingly. You can click anywhere on the map to pull up a GPS coordinate.

Map Demo

Putting your Device on the map is easy:

  1. Go to your device and click on the "Services" tab
  2. Click "Link Service" and scroll down to "GPS Mapper"
  3. The configuration will ask you for the "Marker Type". This is used to set the color and layer for your device. Currently we only support "Gateway" for gateway devices or any other name for a transducer. You can also leave the field blank, but the name you enter will be the prefix to your transducer's name in the popup on the map
  4. Now click on the "Transducers" tab and add a "latitude" and "longitude" transducers. The units don't matter, but we often use "gps". Make sure to select "Actuable" if you want to use a command to manually set the location. You can use "latitude" / "longitude" OR "gps". If you use both, the last one updated will be reflected on the map.

Map Transducers

  1. Click on the "Command" tab and add a command that sets a value for your latitude and longitude. Press the "Run" command and wait a few seconds to refresh the map

Map Commands

  1. Thats it!

Other notes:

  1. Removing the service will remove your device from the map. Feel free to add and remove as often as you like.
  2. You can also create a transducer called "gps" and put coordinates in as lat,lon. For example "40.44,-79.94", without the quotes would be a valid GPS coordinate
  3. We filter out coordinates with 0 in the lat or lon
  4. Some devices like gateways will automatically publish latitude and longitude values, so its easy to place them on the map by adding the service

GPS Mapper Service Internals

The GPS Mapper Service is built using the OpenChirp golang framework. The service subscribes to the latitude, longitude and gps transducers of any device added and generates a static website that uses Leaflet's map interface. Every 10 seconds it generates a file called "oc-geojson.js" that is read by our "index.html" file. The framework keeps a local copy of all coordinates and names in a file called "gpsDB.dat" that is loaded upon restart and updated every time a static map is generated.

The framework also serves dynamic content:

When configuring the service make sure to add a Device configuration for "Marker Type" which is used internal to decide about the marker color or layer.

There are a few modifications that need to be made with the standard leaflet install:

  1. Place our "index.html" file in the root of the leaflet directory
  2. Point the service towards the same directory with the "geojson-path" parameter to generate the dynamic json file that "index.html" reads
  3. Copy the images/marker-icon-red.png file into the leaflet image directory

Building in your go source dir:

> go get ../.
> go build

For usage information see:

NAME:
   gpsMapper-service

USAGE:
   gpsMapper [global options] command [command options] [arguments...]

VERSION:
   1.0

COMMANDS:
     help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --framework-server value    OpenChirp framework server's URI (default: "http://localhost:7000") [$FRAMEWORK_SERVER]
   --mqtt-server value         MQTT server's URI (e.g. scheme://host:port where scheme is tcp or tls) (default: "tls://localhost:1883") [$MQTT_SERVER]
   --service-id value          OpenChirp service id [$SERVICE_ID]
   --service-token value       OpenChirp service token [$SERVICE_TOKEN]
   --log-level value           debug=5, info=4, warning=3, error=2, fatal=1, panic=0 (default: 4) [$LOG_LEVEL]
   --geojson-path value        Path to geojson file for leaflet (default: "oc-geojason.js") [$GEOJSON_PATH]
   --http-port value           Port for serving dynamic content (default: 9000) [$HTTP_PORT]
   --static-update-rate value  Interval in seconds for static content update (default: 30) [$STATIC_UPDATE_RATE]
   --help, -h                  show help
   --version, -v               print the version

COPYRIGHT:
   See https://github.com/openchirp/example-service for copyright information

Clone this wiki locally