Sending Events to an Edge Action

Observations defined on an Octave-enabled edge device, can be configured to process events directly on the device using an Edge Action, thus avoiding a data transfer to the cloud.

The steps below illustrate how to modify the Observation created in the previous topic. In this example, the Observation is configured to send values from the mangoOH Red's built-in light sensor to an Edge Action. The Edge Action then computes the luminosity and sends the result to the mangOH Red's built-in LCD.

  1. Navigate to Device > Observations.
  2. Locate the light Observation created in the Sending Events to the Cloud Immediately section.
  3. Click the edit button to edit the Observation.
  4. Set Send events to to Edge Action and click Save.
  5. Navigate to Device > Edge Actions and click Add Edge Action.
  6. Click on Source Observation and select the Observation edited above.
  7. Click on Edge Action Name and enter a description name for the Edge Action.
  8. Paste the following code into the Code window:
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.