Community Forum B.One Community Forum Zenner Wasserzähler Payload Reply To: Zenner Wasserzähler Payload

  • DEMCAK

    Mitglied
    17. Oktober 2024 um 14:09 Uhr

    function decodeUplink(input) {

    var bytes = input.bytes;

    var status = bytes[0]; // Assuming the first byte contains the status summary bits

    var data = {

    removal_detection: (status & 0x01) >> 0,

    battery_low: (status & 0x02) >> 1,

    battery_end_of_life: (status & 0x04) >> 2,

    hw_error: (status & 0x08) >> 3,

    currently_unused: (status & 0x10) >> 4,

    coil_manipulation: (status & 0x20) >> 5,

    transceiver_monitoring_flag1: (status & 0x40) >> 6,

    transceiver_monitoring_flag2: (status & 0x80) >> 7,

    // … other status bits

    };

    // Assuming the next bytes contain meter values in SP12 format

    var meterValues = [];

    for (var i = 1; i < bytes.length; i += 4) {

    // Day value (4 bytes) assuming little-endian

    var meterValue = bytes[1] + (bytes[2] << 8) + (bytes[3] << 16) + (bytes[4] << 24);

    meterValues.push(meterValue);

    }

    data.meter_values = meterValues;

    return {

    data: data,

    };

    }