function toTagoFormat(object_item, group, prefix = '') {
const result = [];
for (const key in object_item) {
if (ignore_vars.includes(key)) continue;
if (typeof object_item[key] == 'object') {
result.push({
variable: object_item[key].variable || `${prefix}${key}`,
value: object_item[key].value,
group: object_item[key].group || group,
unit: object_item[key].unit,
});
} else {
result.push({
variable: `${prefix}${key}`,
value: object_item[key]
});
}
}
return result;
}
// Check if what is being stored is the ttn_payload.
// Payload is an environment variable. Is where what is being inserted to your device comes in.
if (!payload[0].DATA.variable) {
// Get a unique group for the incoming data.
const group = payload[0].DATA.group || String(new Date().getTime());
payload = toTagoFormat(payload[0].DATA, group);
}