Basic Transformation and Analysis

This topic covers how to create an Edge Action and use it to read values, apply functions, and send data.

An Edge Action contains high-level, JavaScript that runs on the device, allowing you to transform events from observations, and send them to the cloud or to another resource on the device.

Creating an Edge Action to process data involves defining processing instructions (JavaScript code) through the Octave Dashboard and saving it to the Octave-enabled edge device. This code is entered on Octave's Edge Action screen using the screen's Action Runner code editor.

The following example illustrates this by using an Observation to monitor the light sensor included on the mangOH Red and sending the values to an Edge Action. The Edge Action then computes the luminosity and sends the result to the third line of the LCD.

Start by following the steps below to define an Observation for the light sensor:

  1. Navigate to Device > Observations.
  2. Click Add Observation.
  3. Click on Observed resource and select /redSensor/light/value.
  4. Enter a descriptive name into the Observation name field.
  5. Set Send events to to Edge Action.
  6. Leave the remaining fields as their defaults and click Save.

Next, follow the steps below to create the Edge Action that will process events from the Observation:

  1. Navigate to Device > Edge Actions.
  2. Click Add Edge Action.
  3. Click Source Observation and select the Observation created above.
  4. Enter a descriptive name into the Action name field.
  5. Click the Documentation tab. Octave provides a number of example scripts that you can use as a starting point.
  6. Select Show the light value on LCD and copy and paste the code into the Code section. The code should look as follows:
function(event){
  var lightReading = event.value;
  var lightDescription;

  if (lightReading > 1500) {
    lightDescription = "bright"
  } else if (lightReading > 300) {
    lightDescription = "a bit dim"
  } else {
    lightDescription = "dark"
  }

  var s = "It's " + lightDescription + " in here.";

  return {
    "dh://lcd/txt3":[s]
  }
}
  1. Click Save. The logic has now been sent to the device and will execute when an event from an Observation is received by the Edge Action.