embedded_raumsenor_lorawan/chirpstack3_encoder.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

50 lines
1.4 KiB
JavaScript

// ChirpStack3 Encoder for Combined Downlink Packet
// Format: [heating_enable][room_temp_threshold][floor_temp_threshold]
function Encode(fPort, obj, variables) {
var bytes = [];
// Combined packet format (3 bytes)
if (obj.heating_enable !== undefined && obj.room_temp !== undefined && obj.floor_temp !== undefined) {
// Byte 0: Heating enable (0=DISABLED, 1=ENABLED)
bytes[0] = obj.heating_enable ? 1 : 0;
// Byte 1: Room temperature threshold (°C)
bytes[1] = parseInt(obj.room_temp);
// Byte 2: Floor temperature threshold (°C)
bytes[2] = parseInt(obj.floor_temp);
return bytes;
}
// Send interval format (2 bytes): 'i' + minutes
if (obj.send_interval !== undefined) {
bytes[0] = 0x69; // ASCII 'i'
bytes[1] = parseInt(obj.send_interval);
return bytes;
}
// Load configuration format (3 bytes): 'w' + watts (2 bytes big-endian)
if (obj.load_watts !== undefined) {
var w = parseInt(obj.load_watts);
bytes[0] = 0x77; // ASCII 'w'
bytes[1] = (w >> 8) & 0xFF;
bytes[2] = w & 0xFF;
return bytes;
}
return null;
}
// Example usage:
// Combined packet: {"heating_enable": true, "room_temp": 22, "floor_temp": 25}
// Result: [0x01, 0x16, 0x19]
// Send interval: {"send_interval": 5}
// Result: [0x69, 0x05]
// Load configuration: {"load_watts": 400}
// Result: [0x77, 0x01, 0x90]