Hi all!
sorry, but I’m relatively new to LoRa/TTN and also javascript…
I’m getting some data from a meter and trying to see them in thingspeak. I can see some fields in thingspeak channel but not all the fields. Specifically, fields1, 2 and 3 doesn’t update but the rest are ok.
Payload examples:
0010E423010C43707620436F75C8436DCC70705A
0010E423020C40D6D08040BF4280408B8A80D34B
0010E423030CBF5A6ED6BF5CB1EEBF7FD34889AC
0010E423040C43CFF84C43CDB6FC43CEB8987CC7
0010E423050CBF6A23D645822E0E45126E429E99
0010E423060C44B7204544ADD6AB44A3C1440A50
0010E423070C448536DB447DB880438325A708B7
Here is my decoder function, any idea will be appreciated. Thanks!
function Decoder(bytes, port)
{
var meterID = bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3];
var step = bytes[4];
var nbytes = bytes[5];
var bits1 = bytes[6]<<24 | bytes[7]<<16 | bytes[8]<<8 | bytes[9];
var bits2 = bytes[10]<<24 | bytes[11]<<16 | bytes[12]<<8 | bytes[13];
var bits3 = bytes[14]<<24 | bytes[15]<<16 | bytes[16]<<8 | bytes[17];
var crc = bytes[18] << 8 | bytes[19];
var bits; // generica
function bytestofloat(bytes, bits){
var sign = ((bits >>> 31) == 0) ? 1.0 : -1.0;
var e = ((bits >>> 23) & 0xff);
var m = (e == 0) ? (bits & 0x7fffff) << 1 : (bits & 0x7fffff) | 0x800000;
var x = sign * m * Math.pow(2, e - 150);
return x;
}
if (step == 1){
var V1 = bytestofloat(bytes,bits1);
var V2 = bytestofloat(bytes,bits2);
var V3 = bytestofloat(bytes,bits3);
}
if (step == 2){
var I1 = bytestofloat(bytes,bits1);
var I2 = bytestofloat(bytes,bits2);
var I3 = bytestofloat(bytes,bits3);
}
if (step == 3){
var PF1 = bytestofloat(bytes,bits1);
var PF2 = bytestofloat(bytes,bits2);
var PF3 = bytestofloat(bytes,bits3);
}
if (step == 4){
var V12 = bytestofloat(bytes,bits1);
var V23 = bytestofloat(bytes,bits2);
var V31 = bytestofloat(bytes,bits3);
}
if (step == 5){
var PF = bytestofloat(bytes,bits1);
var kWh = bytestofloat(bytes,bits2);
var kVArh = bytestofloat(bytes,bits3);
}
if (step == 6){
var ikWh1 = bytestofloat(bytes,bits1);
var ikWh2 = bytestofloat(bytes,bits2);
var ikWh3 = bytestofloat(bytes,bits3);
}
if (step == 7){
var ekWh1 = bytestofloat(bytes,bits1);
var ekWh2 = bytestofloat(bytes,bits2);
var ekWh3 = bytestofloat(bytes,bits3);
}
return{
field1:ikWh1,
field2:ikWh2,
field3:ikWh3,
field4:PF,
field5:kWh,
field6:V1,
field7:V2,
field8:V3
};
}