Hello Takashi,
Here is an edge action using the light sensor in an observation. as input into the edge action. The edge action also reads the temperature, pressure and humidity sensors.
// Imput resource to this edge action is the light sensor
var light_value = event.value;
console.log("light = " + light_value);
var temperature = 0;
var humidity = 0;
var pressure = 0;
var temp_limit_hi = 80;
var temp_limit_lo = 36;
var humidity_limit = 43;
var msg_type = “”;
var edge_payload = “”;
// read the other Sensors (resources) to get the latest value
var env_obj = JSON.parse(JSON.stringify(Datahub.read("/environment/value",0)));
var temperature = (env_obj.value.temperature * (9/5)) + 32; // Celcius to Farenheit
var pressure = env_obj.value.pressure * 0.0001450377; // Pascal to PSI
var humidity = env_obj.value.humidity;
console.log("temperature = " + temperature);
console.log("pressuree = " + pressure);
console.log("hunidity = " + humidity);
// Read the virtual resources that have the thresholds defined
temp_limit_hi = Datahub.read("/virtual/temp_limit_hi/value",0);
temp_limit_lo = Datahub.read("/virtual/temp_limit_lo/value",0);
humidity_limit = Datahub.read("/virtual/humidity_limit/value",0);
// Is the message an alert or periodic ?
if (temperature >= temp_limit_hi || temperature <= temp_limit_lo || humidity <= humidity_limit) {
msg_type = “alert”
} else {
msg_type = “periodic”
}
// Build the edge payload to send to the Octave cloud
edge_payload = {
“light”: light_value,
“temperature”: temperature,
“pressure”: pressure,
“humidity”: humidity,
“msg_type”: msg_type
}
// Send to an alert virtual JSON resource or virtual periodic JSON resource that have obesravtions
// on them with throttling of 20 secs and 3600 seconds and will be used as input into cloud connectors
if (msg_type == “alert”) {
return {
“vr://vr_alert_payload”: [edge_payload]
};
} else if (msg_type == “periodic”) {
return {
“vr://vr_periodic_payload”: [edge_payload]
};
} else {
return {
“cl://”: [edge_payload]
};
}