Edge Actions

Edge Actions

An Edge Action transforms Events from Observations and routes them to other Resources, or to the Cloud. Transformations are done via JavaScript embedded within the Edge Action.

The JavaScript can be written using Action Runner in the Octave dashboard, or done programmatically via the Edge Action of the Octave REST API.

When an Edge action is assigned to a Device, the JavaScript is sent to the Device and loaded. It is bound to a specific Observation, such that when a new Event is created from the Observation, the JavaScript is executed with the Event as the input parameter.

📘

Note

An Edge Action is like a Cloud Action but runs on physical devices using the "Octave" Edge Package.

The JavaScript within an Edge Action can output new events to be sent to the cloud and set the values of Resources. While an Edge action is executing, it has full access to read and write data from resources. Edge actions are most commonly used to route and/or process data on the edge using locally-available sensor and configuration data.

Reading Events in an Edge Action

When an Event is received in an Edge Action, the event parameter is deserialized from the following JSON.

{
  "value": value,
  "timestamp": 1582827837.235676
}

The JavaScript in an Edge Action can read information about the event via the event parameter. For example, the following code reads the value of a light sensor:

function(event) {
  var lightReading = event.value;
  // ...
}

Creating Events in an Edge Action

The JavaScript in an Edge Action can create an Event by returning a key/value pair where the key specifies the target (e.g. dh for Data Hub).

For example, the following Edge Action sets the value on the LCD screen Resource of a mangOH Red to "Hello!" via the device's Data Hub:

function(event) {
   // Do something with the event
   // ...

   return {
     "dh://lcd/txt1": ["Hello!"]
   }
}

For a list of targets see Output.