37 lines
1.1 KiB
JavaScript
37 lines
1.1 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;
|
|
}
|
|
|
|
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]
|