Setting a Value From an Edge Action

This topic describes how to create and set a value from an edge action.


When writing the logic for an Edge Actions, you will typically begin by reading the Event data that has been Observed, and then set a value (e.g., active an Output (Actuator), display a status, etc.). This topic describes how to set that value in your Action Script's logic.

Sending Data to the Datahub

The following example illustrates an Edge Action that monitors the light sensor included on the Octave Edge Devices, computes the luminosity, and sends the result to the third line of the device's LCD screen.

  1. Create an Observation for the mangOH Red's /redSensor/light/value sensor resource and configure the Observation to send events to an Edge Action.
  2. Create an Edge Action with the following code:
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]

The code reads the light value, concatenates it with some text describing the brightness, and then writes the string to the /lcd/txt3 Resource (third line of LCD screen).

Writing text to the LCD screen is accomplished by returning the string to the Data Hub which is indicated with dh:. For additional information see the Edge Action Runner Reference, and more specifically, that topic's Output section.

  1. Click Save. The logic has now been sent to the Octave Edge device and will execute when an Event from an Observation is received by the Edge Action.


Return syntax

The returned object can include several paths, so several Resources can be updated from a single edge action.

Also, the Action Runner expects an array of objects for each path. As a consequence, even your script provides only one value, you must use the syntax "dh://resource_path": [ resource_value ].
Of course, the value you provide can itself be an array.

Sending Data via Store and Forward

You can optionally use Store and Forward to have your readings stored and then forwarded on a periodic basis rather than sending them immediately to the Datahub. See Sending Data in an Edge Action Using Store and Forward for more information.