Available classes in Omnyvore scripts

Available classes

The following classes will be available by default in each Omnyvore script you write.

BigDataClient

Object which acts as a proxy to access Omnyvore's big data. It can be instantiated as follows:

var bdc = new BigDataClient(topic, env);

Instances of BigDataClient expose the following interface:

  • getAggregatedValue(resourceId, parameterCode, timerange, aggregationOperator) : Double: given a resource id of a thing, retrieve the aggregated value for the measurements which have a given parameter code in the last timerange milliseconds
  • getAggregatedValue(resourceId, parameterCode, start, end, aggregationOperator) : Double: given a resource id of a thing, retrieve the aggregated value for the measurements which have a given parameter code in the time range starting at start milliseconds from UNIX epoch and ending at end milliseconds from UNIX epoch
  • getLatestMeasurement(resourceId, parameterCode) : Measurement: given a resource id of a thing, retrieve last value for the measurements which have a given parameter code

The available aggregation operators are avg, count, value_count, max, min, and sum.

Caution: topic and env are variables available only in channel processing, so for now BigDataClient is not recommended to be used in alarm processing.

Boolean

Object with the same API as a Java's Boolean.

Double

Object with the same API as a Java's Double.

EvaluationResult

Data object that is returned when processing alarms. EvaluationResult objects are compliant to the following JSON Schema:

{
    "persist" : "boolean", // true iff the alarm has to be raised within the Omnyvore platform
    "measurements" : "List<Measurement>" // List (see the class in this page) of Measurements
}

Caution: Additional fields may be found or filled, but their value is likely to be overwritten.

Float

Object with the same API as a Java's Float.

HttpGet

Object which performs HTTP GET calls. It can be instantiated as follows:

var httpGet = new HttpGet(url);

Where url is the URL towards which the call will be made. HttpGet objects have the following interface:

  • send: perform the HTTP GET call

HttpPost

Object which performs HTTP POST calls. It can be instantiated as follows:

var httpPost = new HttpPost(url);

Where url is the URL towards which the call will be made. HttpPost objects have the following interface:

  • addJson(json): add json as the request entity
  • addParam(name, value): add a name-value pair to be used as the request entity
  • send(): perform the HTTP POST call

HttpPut

Object which performs HTTP PUT calls. It can be instantiated as follows:

var httpPut = new HttpPut(url);

Where url is the URL towards which the call will be made. HttpPut objects have the following interface:

  • addJson(json): add json as the request entity
  • addParam(name, value): add a name-value pair to be used as the request entity
  • send(): perform the HTTP PUT call

Integer

Object with the same API as a Java's Integer.

List

Object with the same API as a Java's ArrayList.

Long

Object with the same API as a Java's Long.

Measurement

Data object which is compliant to the following JSON Schema:

{
    "name" : "string", // name of the parameter which corresponds to the processed data
    "value" : "string", // measured value of the parameter
    "when" : "integer" // timestamp (milliseconds from UNIX epoch)
}

Mqtt

Object which acts as a proxy to access Omnyvore's MQTT broker. It can be instantiated as follows:

var mqtt = new Mqtt(topic, env);

Instances of Mqtt expose the following interface:

  • publishOut(channel, data): given the ending part of an MQTT channel, publish a message directed to Omnyvore with data as payload
  • publishOut(channel, data, retained): given the ending part of an MQTT channel, publish a message directed to Omnyvore with data as payload. If retained is true, the broker will retain the message
  • publishIn(channel, data): given the ending part of an MQTT channel, publish a message directed to the thing with data as payload
  • publishIn(channel, data, retained): given the ending part of an MQTT channel, publish a message directed to the thing with data as payload. If retained is true, the broker will retain the message

Caution: topic and env are variables available only in channel processing, so for now Mqtt is not recommended to be used in alarm processing.

Object

Object with the same API as a Java's Object.

OMV

Utils class whose methods can be used to ease several tasks:

  • byte2int(byte) : int: return the byte converted to an integer (not unsigned)
  • decodeHex(hex) : byte[]: get the byte array corresponding to the decoding of the hexadecimal string hex
  • encodeHex(byteBuffer) : String: get the textual representation of byteBuffer as an hexadecimal string
  • getRange(byteBuffer, start, end) : ByteBuffer: byteBuffer is a ByteBuffer from which the bytes from the start index (inclusive) to the end index (exclusive)
  • readBool(byteBuffer, position) : boolean: return true iff the bit at a given position of the byteBuffer is true
  • readUInt8(byteBuffer) : int: return the byteBuffer converted to a 8-bit integer (with little endianess)
  • readUInt16(byteBuffer) : int: return the byteBuffer converted to a 16-bit integer (with little endianess)
  • readUInt16BE(byteBuffer) : int: return the byteBuffer converted to a 16-bit integer (with big endianess)
  • readUInt24(byteBuffer) : int: return the byteBuffer converted to a 24-bit integer (with little endianess)
  • readUInt32BE(byteBuffer) : long: return the byteBuffer converted to a 32-bit integer (with big endianess)
  • readUInt32(byteBuffer) : long: return the byteBuffer converted to a 32-bit integer (with little endianess)
  • readUInt64(byteBuffer) : long: return the byteBuffer converted to a 64-bit integer (with little endianess)
  • toString(byteBuffer) : String: encode byteBuffer as an UTF-8 string

Reply

Data object that is returned when processing command replies. Reply objects are compliant to the following JSON Schema:

{
    "correlationId" : "string", // identifier used to correlate the reply to the command sent to the thing
    "payload" : "string", // text containing the payload of a reply
    "measurements" : "List<Measurement>", // List (see the class in this page) of Measurements
    "when" : "integer" // timestamp (milliseconds from UNIX epoch)
}

Caution: Additional fields may be found or filled, but their value is likely to be overwritten.

SafeEnvironment

This type of object is injected as env and it comes with the following interface:

  • getProperties() : Set<String>: retrieves the set of all the properties present in the current environment
  • getProperty(key): retrieves the value of a property called key

Caution: SafeEnvironment is currently injected only in alarm processing scripts.

Short

Object with the same API as a Java's Short.

String

Object with the same API as a Java's String.

Utils

Class equivalent to OMV.