// 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]