Global Variables
Concept
Sometimes you need Data to persist between the call of a payload decoder. This is normally done by using global environment variables that store the data between function calls.
Access Database Fields
On Datacake this can be achieved by creating a dedicated field in the Database Section of your Datacake Device and by using this as the storage for this data.
function decoder() {
// get current value from field in Database
var numberOfCalls = measurements.NUMBER_OF_CALLS.value;
// do some processing
numberOfCalls = numberOfCalls + 1;
// return that field in order to write new value into database
return [
{ "field": "NUMBER_OF_CALLS", "value": numberOfCalls }
]
}Time between changes
Storing data between payload decoder function calls can also be used to measure the time elapsed between a change of a value. This can be done by accessing not only the current value of a Database-Field but also the timestamp.
Last updated
Was this helpful?