Tracking the location of your IoT Central devices

Recently IoT Central added location tracking.

In the past, it was already possible to add a location to your IoT Central devices. And these locations were shown on a map. But these locations were fixed, part of the device template properties. So it was only present in the metadata.

But now we can pass a location in the telemetry which is produced by your device.

Let’s see how it’s done and how the location is integrated into the various IoT Central dashboards.

Adding location in your telemetry

When sending a location, your message has to look like this:

{
  "temperature":11.0,
  "location":
  {
    "lat":48.0,
    "lon":19.0,
    "alt":40000.0
  },
  "devicestatus":"2"
}

If the code of your device is written in C#, the C# equivalent looks like this:

public class Telemetry
{
  public decimal temperature { get; set; }
  public Location location { get; set; }
  public string devicestatus { get; set; }
}

public class Location
{
  public decimal lat { get; set; }
  public decimal lon { get; set; }
  public decimal? alt { get; set; }
}

There are several interesting values to point at:

  1. The fields ‘lat’ and ‘lon’ are obligated. The ‘alt’ is optional
  2. The location is a nested value within the telemetry message
  3. The ‘devicestatus’ field is of type string

We will see the status field later on.

Device template

Once we have established the message structure, adding a location to the DeviceTemplate is quite trivial. Start with adding a location measurement to your template:

il01

This measurement is pretty simple to fill in:

il02

Once added, a map visualization is available in the device template for the location. You can choose to see how the latest location or the location history looks like.

il03

Please add a State measurement too. It will represent the ‘devicestatus’ value. In my example, I expect 1,2,3 for low, medium, high. Give the values distinctive colors.

Before we look at telemetry arriving from an actual device, we first create a device dashboard.

Device template dashboard

Go to the dashboard tab page.

There we can add a Map widget and reference the Location field:

il04

And we can also reference the State measurement. This will change the color of your location pin.

The map can either show the current location or the history for a certain time range. In this example, I show the history of the last 30 minutes.

Now go to your device or the simulation which is also created. Check out the location in the device dashboard:

il05

The telemetry arrives and the history of the device is shown on the map. The latest pin resembles the color of the state at that moment. The pins also support pop-up windows. In this window, the location is shown as an actual human-readable address, thanks to automatic geocoding. And the state is repeated in the pop-up window.

Note: the actual location sent from the device is not shown. I do not know how to get a look at the raw location telemetry.

This is only one device. There will be other devices which implement the same device template. Can we show multiple devices on one map?

Device set dashboard

IoT Central supports the concept of device sets. When a device template is created, also a device set is created which contains every device implementing that device template.

A device set has a dashboard too. And on that map, the current locations of all devices in the set is shown:

il06

Again, the color of the pin represents the state of the last measurement.

IoT Central main dashboard

Finally, the last dashboard I demonstrate is the main dashboard of your IoT Central.

As with the other dashboard, again we can add map widgets.

These widgets are equal to the widgets of the device template dashboard map. But we are able to add multiple maps, each representing one device:

il07

In this example, I show two different devices. To the left, I show the history of a simulated device. To the right, I show the actual location of a real device.

Conclusion

The new location measurement is definitely a great addition to IoT Central and makes IoT Central even more versatile. Now we have dashboards with live device telemetry.

There are several dashboards all with their own view on device locations. So start mixing and matching your own unique interface.

I like the reverse-geocoding feature but I would like to be able to turn it on and of. For now, it seems we have to export the telemetry before we can see the raw values.

Advertenties

Geef een reactie

Vul je gegevens in of klik op een icoon om in te loggen.

WordPress.com logo

Je reageert onder je WordPress.com account. Log uit /  Bijwerken )

Google photo

Je reageert onder je Google account. Log uit /  Bijwerken )

Twitter-afbeelding

Je reageert onder je Twitter account. Log uit /  Bijwerken )

Facebook foto

Je reageert onder je Facebook account. Log uit /  Bijwerken )

Verbinden met %s