I just got this code (i’m no js expert - just a hack)
//
// using nickname tag, write this dynamic data to the mutable bucket
//
const writeValue = {
variable: myNickname.value,
value: myWaterSoil,
unit: “Percent”,
};
//
// before writing, find out if the variable exists. if it does
// use editData, if it doesn’t use sendData.
//
// to find out if it exists, use getData
//
const readValue = {
variable: myNickname.value,
query: “last_item”,
};
//
// get device data using the nickname
//
const getResult = await outDevice.getData(readValue);
context.log(" from getResult ", getResult );
if( getResult.length ) {
const dataId = getResult[0].id;
context.log(" FOUND - Updating ", dataId );
writeValue[“id”]= dataId;
const Result = await outDevice.editData(writeValue);
}
else {
context.log(" NOT found - Writing ", getResult );
const Result = await outDevice.sendData(writeValue);
}
}
module.exports = new Analysis(init);