Reading Event Data in an Edge Action
When writing the code for an Edge Action, you will usually base your logic around the value from the incoming Event such as the value of a sensor reading.
When an Event is received in an Edge Action, the event
parameter contains the Event's data:
function(event) {
}
The Event is received as a JSON object on the Octave Edge device and contains the following fields depending on the device's firmware:
Firmware Prior to 3.4:
{
"timestamp":<double precision>,
"value":"<string-formatted JSON>"
}
Firmware 3.4+:
{
"source":"<observation name | resource path>",
"timestamp":<double precision>,
"value":"<string-formatted JSON>"
}
source
(firmware 3.4+ only): The Observation name or path to the Resource for which the Event is related.timestamp
: The date/time when the event was received (e.g., 1582827837.235676).value
: The Event's data (e.g., a sensor reading).
The JavaScript in an Edge Action can read this information via the event
parameter. For example, the following code reads the value of a light sensor:
function(event) {
var lightReading = event.value;
// ...
}
After reading the Event's value
, you may then want to perform some logic and then set a value. For additional information see the Edge Action Runner Reference.
Updated about 3 years ago