Helios-P Drucksensor Dataconverter .js

Sie suchen den Dataconverter (Payload Decoder) für den Drucksensor Helios-P?

Helios-P Drucksensor Payload Decoder LoRaWAN®

function decodeUplink(input) {
  
    function uncomplement(val, bitwidth) {
        var isnegative = val & (1 << (bitwidth - 1));
        var boundary = (1 << bitwidth);
        var minval = -boundary;
        var mask = boundary - 1;
        return isnegative ? minval + (val & mask) : val;
    } 
  
    var decoded = {};
    var bytes = input.bytes;
    
    if(input.fPort == 1){// TELEMETRY
      
        //decode header
        decoded.base_id = bytes[0] >> 4;
        decoded.major_version = bytes[0] & 0x0F;
        decoded.minor_version = bytes[1] >> 4;
        decoded.product_version = bytes[1] & 0x0F;
        decoded.up_cnt = bytes[2];
        decoded.battery_voltage = ((bytes[3] << 8 ) | bytes[4]) / 1000.0;
        decoded.internal_temperature = bytes[5] - 128;
                
        // Reason of this uplink
        // reasonRaw & 0x01 -> Regular send period 
        // reasonRaw & 0x02 -> Measured delta exceeds threshold
        // reasonRaw & 0x04 -> Critical Alarm, Temperature or Pressure critical
        decoded.reasonRaw = bytes[6];

        // One ore more alarms
        // alarmRaw & 0x01 -> Pressure low
        // alarmRaw & 0x02 -> Pressure high
        // alarmRaw & 0x04 -> Pressure critical
        // alarmRaw & 0x10 -> Temperature low 
        // alarmRaw & 0x20 -> Temperature high
        // alarmRaw & 0x40 -> Temperature critical
        decoded.alarmRaw = bytes[7];

        // Pressure reading status
        // OK = 0 (No Problems)
        // ERROR_PROBE = 1 (Probe not working correctly or not connected)
        // ERROR_ADC = 2 (Problem with adc on helios board)
        // ERROR_VALUE = 3 (Measured Value out of range, probe or board issue, try differnt probe)
        decoded.status = bytes[8];

        // Pressure in mBar
        decoded.pressure = bytes[9] << 8 | bytes[10];

    }
  
  return {
    data: decoded,
    warnings: [],
    errors: []
  };
  
}