const result = [];
const devices_mac = { //tabela de macs dos medidores
"34:94:54:d1:f5:14":"ufpe"
};
const unidades = { //tabela de unidades
voltage:"V",
current:"A",
pf:"",
power:"W"
}
for (const key in payload.data.measures[0]){
const group = payload.data.measures[0].group || String(new Date().getTime());
const unidade = unidades[key];
device = devices_mac[payload.info.mac];
result.push({
variable: `${device}.${key}_faseA`,
value: payload.data.measures[0][key].toFixed(2),
unit: `${unidade}`,
group: group
});
};
for (const key in payload.data.measures[1]){
const group = payload.data.measures[1].group || String(new Date().getTime());
const unidade = unidades[key];
device = devices_mac[payload.info.mac];
result.push({
variable: `${device}.${key}_faseB`,
value: payload.data.measures[0][key].toFixed(2),
unit: `${unidade}`,
group: group
});
};
for (const key in payload.data.measures[2]){
const group = payload.data.measures[2].group || String(new Date().getTime());
const unidade = unidades[key];
device = devices_mac[payload.info.mac];
result.push({
variable: `${device}.${key}_faseC`,
value: payload.data.measures[0][key].toFixed(2),
unit: `${unidade}`,
group: group
});
};
payload[