Hi All.
Using Datacake to decode the Eastron. they had a template as below… But the issue I am having is i’m not getting all the parameters. Could someone please help me tweak it?
Thanks
function Decoder(bytes, port) {
var decoded = {};
if ( bytes[4] == 01) {
decoded.IMPORT_KWH = (bytesToFloat(bytes.slice(06, 10))).toFixed(2);
decoded.VOLTAGE = (bytesToFloat(bytes.slice(10, 14))).toFixed(2);
decoded.current = (bytesToFloat(bytes.slice(14, 18))).toFixed(3);
decoded.ACTIVE_POWER = (bytesToFloat(bytes.slice(18, 22))).toFixed(0);
decoded.FREQUENCY = (bytesToFloat(bytes.slice(22, 26))).toFixed(1);
decoded.VOLTAGE_2 = (bytesToFloat(bytes.slice(26, 28))).toFixed(1);
decoded.VARIABLE1 = (bytesToFloat(bytes.slice(28, 30))).toFixed(1);
decoded.VOLTAGE_3 = (bytesToFloat(bytes.slice(30, 34))).toFixed(1);
decoded.VARIABLE4 = (bytesToFloat(bytes.slice(34, 38))).toFixed(1);
}
try {
decoded.LORA_RSSI = (!!normalizedPayload.gateways && !!normalizedPayload.gateways[0] && normalizedPayload.gateways[0].rssi) || 0;
decoded.LORA_SNR = (!!normalizedPayload.gateways && !!normalizedPayload.gateways[0] && normalizedPayload.gateways[0].snr) || 0;
decoded.LORA_DATARATE = normalizedPayload.data_rate;
} catch (e) {
console.log(e);
}
return decoded;
}
function bytesToFloat(bytes) {
var bits = bytes[0]<<24 | bytes[1]<<16 | bytes[2]<<8 | bytes[3];
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 f = sign * m * Math.pow(2, e - 150);
return f;
}