Skip to content
English
  • There are no suggestions because the search field is empty.

Neptun Dataconverter in .js

You are looking for the .js Payload Decoder for the Neptune Level Sensor?

Here you will find the .js Payload Decoder for the Neptune Level SensorNeptun senti 2.2-1

Neptun 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;
    

    var subtypedict = {1:"radar-peaks", 2: "ultrasonic-peak"};

    if(input.fPort == 1){//TELEMETRY
        
        var moduleid = bytes[0] >> 4;
        var versionMajor= bytes[0] & 0x0F;
        var versionMinor= bytes[1] >> 4;
        var versionSub = bytes[1] & 0x0F;
            
        if ( moduleid == 1 && versionMajor == 1 && versionMinor >= 1 && versionSub == 1){//MODULE == 1 (Sentiface), MAJOR == 1, MINOR >=1, SUBTYPE == 1 (Radar)
            
            //Attributes
            decoded.versionMajor = versionMajor;
            decoded.versionMinor = versionMinor;
            decoded.versionSub = versionSub;
            decoded.model= "radar-peaks";
            decoded.networkType ="lorawan";
            decoded.networkSubType ="tti";
            decoded.firmwareType = "SENTOS2";
            
            ////Telemetry
            //8 Bit Uplink Count for diagnostic purposes
            decoded.up_cnt = bytes[2];
            //Battery-Voltage in Volts
            decoded.battery_voltage = (bytes[3] << 8 | bytes[4]) / 1000.0;
            //Internal temperature in degrees C.
            decoded.internal_temperature = bytes[5] - 128.0;
                  //Indicates wheter the uplink is regular or irregular (delta or vandalism alarm)
                  decoded.alarm = bytes[6];
            //When peaks are sorted by amplitude, this is the distance to the object with the biggest amplitude (default).
            //Otherwise, this is the distance to the nearest detected object.
            decoded.distance_max_peak = bytes[7] << 8 | bytes[8];
            decoded.distance_quality = 0;
            //Success of data acquisition. Flase indicates SW/HW error
            decoded.detection_success =  bytes[9]?true:false;
            //Number of detected peaks (objects). 0 means that no reflection reaches threshold.
            decoded.detected_peaks = bytes[10];

            ////Additional Telemety
            
            //The sensor transmits an array of length <detected_peaks>.
            //For every peak, distance and amplitude are transmitted
            //To ensure support with all data converter implementations,
            //we generate a key for every entry and add a key value pair
            //to the decoded object
            
            var offset = 11;
            var i = offset;

            var n = 1;
            for(i; i+4 <= (offset+decoded.detected_peaks*4);i+=4){
              
        
               var distance_mm = bytes[i]  << 8 | bytes[i+1];
               var amplitude = uncomplement(bytes[i+2] << 8 | bytes[i+3],16);
               
                if(amplitude < 0){
                    amplitude = 0;
                }
               
               
               decoded["rd_"+n] = distance_mm;
               decoded["ra_"+n] = amplitude;
               if(n==1){
                 if(decoded.versionMinor >= 3){
                  decoded.distance_quality = amplitude/10;
                 }else{
                  decoded.distance_quality = (amplitude*distance_mm)/3000000;
                 }
               }
               n++;
   

               
            }
            
        }else if ( moduleid == 1 && versionMajor == 1 && versionMinor >= 1 && versionSub == 2){//MODULE == 1 (Sentiface), MAJOR == 1, MINOR >=1, SUBTYPE == 2 (Ultraschall)
            
            //Attributes
            decoded.versionMajor = versionMajor;
            decoded.versionMinor = versionMinor;
            decoded.versionSub = versionSub;
            decoded.model= "sonar-peaks";
            decoded.networkType ="lpwan-ism";
            decoded.networkSubType ="lorawan";
            decoded.firmwareType = "SENTOS2";
            
            ////Telemetry
            //8 Bit Uplink Count for diagnostic purposes
            decoded.up_cnt = bytes[2];
            //Battery-Voltage in Volts
            decoded.battery_voltage = (bytes[3] << 8 | bytes[4]) / 1000.0;
            //Internal temperature in degrees C.
            decoded.internal_temperature = bytes[5] - 128.0;
            
                  decoded.sonic_status = bytes[6];
                  
                  if(bytes[6] === 0){
                      decoded.detection_success = true;
                      decoded.detected_peaks = 1;
                      decoded.distance_quality = 1;
                  }else{
                      decoded.detection_success = false;
                      decoded.detected_peaks = 0;
                      decoded.distance_quality = 0;
                  }
            
            decoded.distance_max_peak = (bytes[7] << 8 | bytes[8])*10;
            
            
        }    
    }
     
  
  return {
    data: decoded,
    warnings: [],
    errors: []
  };
  
  
  
}

Documentation Links 

 You can find the links for further documentation on Neptun here: