functiondecoder() {// get current value from field in Databasevar 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.
functiondecoder(bytes, port) {// relative change between messages will reset to zero with every sensor uplinkvar relativeNumber = bytes[0]; // get current value from field in Databasevar absoluteNumber = measurements["ABSOLUTE_CHANGE"].value;// add relative change to absolute number absoluteNumber = absoluteNumber + relativeNumber;// store back absolute numberreturn [{ field:"ABSOLUTE_CHANGE", value: absoluteNumber }]}