embedded_raumsenor_lorawan/chirpstack3_decoder.js
Jochen Gojowsky 0287921b38 add energy tracking: 15-byte payload, power consumption accumulation
- Firmware: energy.c/h tracks relay ON-time and uptime via k_uptime_get,
  load_watts (default 400W) persistent via Zephyr Settings API
- Payload extended from 7 to 15 bytes (backwards compatible):
  relay ON-time (uint24), uptime (uint24), load in watts (uint16)
- New 'w' downlink for load configuration
- Fix downlink handler: 'i'/'w' commands now checked before combined packet
- Server: g2h_rs_energy_tracking table for lifetime power_consumption_wh,
  reboot detection via uptime vs real elapsed time
- Decoder/encoder and docs updated
2026-02-19 17:17:30 +01:00

34 lines
1.0 KiB
JavaScript

// Decode decodes an array of bytes into an object.
// - fPort contains the LoRaWAN fPort number
// - bytes is an array of bytes, e.g. [225, 230, 255, 0]
// - variables contains the device variables e.g. {"calibration": "3.5"}
// The function must return an object, e.g. {"temperature": 22.5}
function Decode(fPort, bytes, variables) {
// Hilfsfunktion: 16-Bit signed Big Endian lesen
function readInt16BE(b0, b1) {
var val = (b0 << 8) | b1;
if (val & 0x8000) val = val - 0x10000;
return val;
}
if (bytes.length < 7) {
return { error: "invalid payload length" };
}
var d = {};
d.heating = readInt16BE(bytes[0], bytes[1]) / 100.0;
d.heatingFloor = readInt16BE(bytes[2], bytes[3]) / 100.0;
d.airHumidity = readInt16BE(bytes[4], bytes[5]) / 100.0;
d.switch = bytes[6];
if (bytes.length >= 15) {
d.relayOnTime = (bytes[7] << 16) | (bytes[8] << 8) | bytes[9];
d.uptime = (bytes[10] << 16) | (bytes[11] << 8) | bytes[12];
d.loadWatts = (bytes[13] << 8) | bytes[14];
}
return d;
}