Inner Collections API
Connector functions JS API guide for inner collections
This file provides methods to collect data inside a connector function script execution. These methods belong to collection
global object.
JS API
addDatapoint(datastreamId, value, at, source, sourceInfo)
Builds a datapoint object and adds it to the specified datastream in the datastreams list in the collection
global object.
Kind: global function
Returns: Void
Param | Type | Description |
---|---|---|
datastreamId | string | Datastream identifier by which the datapoint will be identified. |
value | any | Collected value. If not provided null will be set. |
at | number | Number with collection timestamp in seconds. If not provided null will be set. |
source | string | String with source name. If not provided null will be set. |
sourceInfo | string | String with source description. If not provided null will be set. |
Example of use:
var now = Date.now() / 1000;
collection.addDatapoint('device.name', 'collected name from cf', now,'mySource','mySourceInfo');
setFeed(datastreamId, feed)
Sets the feed name to a specific datastream in the datastreams list in the collection
global object.
Kind: global function
Returns: Void
Param | Type | Description |
---|---|---|
datastreamId | string | Datastream identifier by which the datapoint will be identified. |
feed | string | The feed name to set to the specified datastream. |
Example of use:
collection.setFeed('device.name', 'myFeed');
send()
Sends a collection message to the OpenGate’s collection messages flow using the datastreams list in the collection
global object, after that this list is cleaned.
Kind: global function
Returns: Void
Example of use:
collection.send();
getValue(datastream, dpIndex)
Sarch datapoint value for specified datastreamId. It is possible to specify datapoint index inside the datastream. If not found null value will be returned
Kind: global function
Returns: *
Param | Type | Description |
---|---|---|
datastream | string | Datastream identifier which value must be returned |
dpIndx | number | Datapoint index. If not defined first datapoint will be returned |
Example of use:
var dpValue = collection.getValue('device.name');
// dpValue will be 'collected name from cf'