Access Measurements


The global measurements object allows you to access the device's current measurements. It is structured like this:

  "BATTERY": {
    "field_name": "BATTERY",
    "timestamp": "1600378287",
    "value": 3.301
    "field_name": "SOIL_CONDUCTIVITY",
    "timestamp": "1600378287",
    "value": 121

Code Example

function decoder() {
    // get current value from field in Database
    var field_in_db = measurements.FIELD_IN_DB.value;

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.

function decoder(bytes, port) {
    // relative change between messages will reset to zero with every sensor uplink
    var relativeNumber = bytes[0]; 
    // get current value from field in Database
    var absoluteNumber = measurements["ABSOLUTE_CHANGE"].value;
    // add relative change to absolute number
    absoluteNumber = absoluteNumber + relativeNumber;
    // store back absolute number
    return [{
        field: "ABSOLUTE_CHANGE",
        value: absoluteNumber

Last updated