// 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; }