RAPIFIRE

Blog

What is SenML?

Introduction

SenML is a sensor markup language that aims to simplify gathering data from different devices across the network. It simply is JSON containing named events together with an associated value and unit. RAPIFIRE provides a very useful subset of it's core functionality.

Here's an example of a minimal SenML message:

{"e":[{"n":"temp", "v":21.5}]}

The top level fields are:

  • e - events, a mandatory field containing array of events
  • bn - base name, an optional field that replaces name if not provided or acts as a name prefix for every event
  • bu - base unit, an optional field that acts as a unit if there is no unit provided for a particular event
  • bt - base time, an optional field that acts as a time for events

Every event object inside the events array may contain fields:

  • n - name, required unless a base name is provided
  • v - numeric value, required unless another value field is provided
  • sv - string value, required unless another value field is provided
  • bv - boolean value, required unless another value field is provided
  • t - time, expressed as milliseconds from 1970-01-01T00:00:00Z. If the base time is provided then it acts as a delta milliseconds and will be added to the base time.
  • u - unit, should be formatted as per SenML spec. For a full list of supported units see chapter 11.1 of SenML specification.

Examples

{"e":[{"n":"min", "v": 5},
      {"n":"max", "v": 23}],
 "bn":"temp/"}

The first event will be saved with the value 5 and the name temp/min. The second event will be saved with the value 23 and the name temp/max . No default unit or time data will be associated with those events.

{"e":[{"n":"direction", "sv":"N"},
      {"n":"speed", "v":33, "u":"m/s"}],
 "bn":"wind/",
 "bt":1448363044635}

This message came from a sensor that measures wind speed and direction. There are two measurements named wind/direction and wind/speed. The speed event additionlly has unit information. Both measurements happened at 12:04:04, 2015-11-24 as there is a base time provided (as milliseconds).

{"e":[{"n":"direction", "sv":"N"},
      {"n":"speed", "v":33, "u":"m/s"},
      {"n":"direction", "sv":"N/W", "t":60000},
      {"n":"speed", "v":29, "u":"m/s", "t":60000},
      {"n":"direction", "sv":"N", "t":120000},
      {"n":"speed", "v":27.5, "u":"m/s", "t":120000}],
 "bn":"wind/",
 "bt":1448363044635}

This message is similar to above one. Due to various reasons we may want to send a few measurements all at once for example to save bandwidth or accumulate more events as the network was offline. The time at which the events happened are calculated by adding the t value to the bt base time value. For example the N/W direction event is t 6000 millisec + bt 1448363044635 millisec = 1448363050635 millisec from 1970-01-01T00:00:00Z which is Tue, 24 Nov 2015 11:04:10 GMT.

RAPIFIRE SenML Extensions

On top of the fields provided by SenML specification, one can use our extensions:

  • jv - json value, SenML being a JSON itself may be extended with your own JSON message
  • lat - latitude, treated as 0 if omitted, useful for location services
  • lng - longitude, treated as 0 if omitted, useful for location services
{"e":[{"lat":52.24, "lng":16.55, "t":144836304463, 
       "jv":{"city":"Poznań", "population":1100000}},
      {"lat":53.02, "lng":18.37, "t":1448367722613,
       "jv":{"city":"Toruń", "population":297646}}],
 "bn":"trip"}