# Octave sample source code for light sensor demo

**URL:** <https://forum.sierrawireless.com/t/octave-sample-source-code-for-light-sensor-demo/25935>\
**Category:** Octave App Sample\
**Tags:** faq\
**Created:** [January 12, 2022, 12:02am UTC](https://forum.sierrawireless.com/t/octave-sample-source-code-for-light-sensor-demo/25935 "2022-01-12T00:02:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![takashi\_shiina](https://avatars.discourse-cdn.com/v4/letter/t/e9bcb4/32.png) [@takashi\_shiina](https://forum.sierrawireless.com/u/takashi_shiina)\
**Post date:** [January 12, 2022, 12:02am UTC](https://forum.sierrawireless.com/t/octave-sample-source-code-for-light-sensor-demo/25935/1 "2022-01-12T00:02:33Z")

</div>

Please provide sample source code for light sensor with mangOH yellow

Our customer would like to use their sensor with FX30 (WP7702) and upload these data to octave cloud.  
To add their sensor, our customer would like to know how to add their code to FX30.  
As sample source code, I think that it is better for light sensor with mangOH yellow because SWI already have Octave demo. Can you provide light sensor Octave demo SW to us as sample source code?

---

<div class="post-metadata">

**Author:** ![djudkins](https://avatars.discourse-cdn.com/v4/letter/d/7ea924/32.png) [@djudkins](https://forum.sierrawireless.com/u/djudkins)\
**Post date:** [January 12, 2022, 5:23pm UTC](https://forum.sierrawireless.com/t/octave-sample-source-code-for-light-sensor-demo/25935/2 "2022-01-12T17:23:50Z")

</div>

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]

};

}
