Channel

Channels are the means by which things deliver information to Omnyvore. More technically speaking, channels are bound to topics and enable online processing for the payload of incoming messages.

For example, a stove may pack several measurements in a single message payload such as <TEMPERATURE>;<HUMIDITY>;<CONSUMPTION>. Therefore, the message 300;40;3 should cause Omnyvore to store 300K as the temperature, 40% of humidity, and 3kW consumed in its data storage. In the following subsections, we will illustrate you how Omnyvore makes this possible for you.


Create a new channel

Select the Add button in the top right corner of the tab: Add button in Channel list view

Then, you can configure the new channel by filling out a dedicated window:

  • Name: mnemonic name for the channel;
  • Description: textual explanation which you can (optionally) provide for the channel;
  • Topic: suffix (ending part) of the topic over which data will be sent;
  • Payload processing: either a regular expression or a script used to process the incoming payload. Creation window for channels

Edit an existing channel

To modify an existing channel, click on it from the channel list and then an editing window similar to the one used at creation time will appear. Nevertheless, this window has also the test feature, which allows you to test channels before sending actual data from the device: this utility might be useful if you want to perform some dry runs before committing some modifications to an already existing script. Payload processing tests are described more in detail in the Script section.


Delete an existing channel

To delete an existing channel, click on it from the channel list and then an editing window similar to the one used at creation time will appear. At this point, you just have to click on the Delete link in the bottom left corner of the window.


Processing data with Omnyvore DSL

With Omnyvore's DSL (Domain Specific Language), you can process data avoiding all the nitty-gritty required to write a Javascript snippet. When using this option (which is called Editor in the Edit channel window), you can write an expression which will be used to parse incoming data. Writing these expressions is quite simple: you just have to compose a template which will be used to parse the payload. As a result, when Omnyvore encounters a PAR(parameterCode) will generate and store in its big data a measurement for the parameter parameterCode.

Hereafter there are some examples, in which:

  • # Expression is the expression written in the editor
  • # Payload is the textual payload sent by the thing
  • # Outcome is what happens when Omnyvore applies the expression to the payload
Simple payload
# Expression
PAR(speed)
# Payload
24
# Outcome
Omnyvore stores a measurement for the parameter 'speed' with a value of 24
Payload with semicolon-separated values
# Expression
PAR(lat);PAR(lon)
# Payload
42;67.59
# Outcome
Omnyvore stores two measurements:
- a measurement for the parameter 'lat' with a value of 42
- a measurement for the parameter 'lon' with a value of 67.59
JSON payload
# Expression
{ "h2o": PAR(h2o), "hcl": PAR(hcl) }
# Payload
{ "h2o": 56, "hcl": 3 }
# Outcome
Omnyvore stores two measurements:
- a measurement for the parameter 'h2o' with a value of 56
- a measurement for the parameter 'hcl' with a value of 3

Processing data with Omnyvore scripts

Even if Omnyvore's DSL is fairly convenient for a number of cases, you might need something more complex to process incoming data. For example, how to cope with a JSON payload which has optional fields? Or how to conditionally publish a command on MQTT when a given value is received for a specific parameter? Omnyvore scripts can deal with all this complex logic by letting you write Javascript code which will be executed when data is processed.

Omnyvore scripts for channels return a List of Measurements.

Hereafter there is an example of scripts which perform the same operation as the examples which have been provided for Omnyvore's DSL.

Simple payload
// deals with spaces at the beginning and at the end of the string, which was not possible with Omnyvore's DSL
var speed = OMV.toString(payload).trim();
var now = (new Date()).getTime();
var returnedList = new List();
returnedList.add(new Measurement('speed', speed, now));
return returnedList;
Payload with semicolon-separated values
var position = OMV.toString(payload).trim();
var now = (new Date()).getTime();
var positionArray = position.split(';');
var lat = java.lang.Double.parseDouble(OMV.toString(positionArray[0].trim()));
var lon = java.lang.Double.parseDouble(OMV.toString(positionArray[1].trim()));
var returnedList = new List();
returnedList.add(new Measurement('lat', lat, now));
returnedList.add(new Measurement('lon', lon, now));
return returnedList;
JSON payload
var obj = OMV.toString(payload).trim();
var now = (new Date()).getTime();
var jsonObj = JSON.parse(obj);
var h2o = obj.h2o;
var hcl = obj.hcl;
var returnedList = new List();
returnedList.add(new Measurement('h2o', h2o, now));
returnedList.add(new Measurement('hcl', hcl, now));
return returnedList;

For more details on which classes you can use in Javascript snippets, please refer to our appendix.