Access Measurements

Concept

The global measurements object allows you to access the device's current measurements. It is structured like this:
1
{
2
"BATTERY": {
3
"field_name": "BATTERY",
4
"timestamp": "1600378287",
5
"value": 3.301
6
},
7
"SOIL_CONDUCTIVITY": {
8
"field_name": "SOIL_CONDUCTIVITY",
9
"timestamp": "1600378287",
10
"value": 121
11
}
12
}
Copied!

Code Example

1
function decoder() {
2
3
// get current value from field in Database
4
var field_in_db = measurements.FIELD_IN_DB.value;
5
6
}
Copied!

Building Counters

If you want to build absolute counters you can use the database access on a decoder in order to read the currently stored value, add a new count and store back the new and updated count. We show you how you can do that.
1
function decoder(bytes, port) {
2
3
// relative change between messages will reset to zero with every sensor uplink
4
var relativeNumber = bytes[0];
5
6
// get current value from field in Database
7
var absoluteNumber = measurements["ABSOLUTE_CHANGE"].value;
8
9
// add relative change to absolute number
10
absoluteNumber = absoluteNumber + relativeNumber;
11
12
// store back absolute number
13
return [{
14
field: "ABSOLUTE_NUMBER",
15
value: absoluteNumber
16
}]
17
18
}
Copied!
Export as PDF
Copy link