Data decoding payload

Hello ,
I am new at this and i am trying to figure out how to decode my data .

I’m using a Dragino distance detection sensor .
I know that the server encode the data for security reasons .

Can anyone help me how to decode my data .

For example i have this kind of payload .
image

And as for this , which one is better to use for a beginner ?

Thank you for your help

For CODEC, use "Custom JavaScript codec, and then if your device is this one then in the top window, copy and paste the codec which you will find in the device document library effectivly this is what you need:

function Decode(fPort, bytes, variables) {
  // Decode an uplink message from a buffer
  // (array) of bytes to an object of fields.
  var len=bytes.length;
  var value=(bytes[0]<<8 | bytes[1]) & 0x3FFF;
  var batV=value/1000;//Battery,units:V
  
  var distance = 0;
  if(len==5)  
  {
   value=bytes[2]<<8 | bytes[3];
   distance=(value);//distance,units:mm
   if(value<20)
    distance = "Invalid Reading";
  }
  else
   distance = "No Sensor";
   
  var interrupt = bytes[len-1]; 
  return {
       Bat:batV ,
       Distance:distance,
       Interrupt_status:interrupt
  };
}

I would however recommend that if you are just starting out, maybe start with Chirpstack v4 and then import all the device codecs.

Trust me, this will make your life much easier… :slight_smile:

thank you so much for your help .
i updated the device profile with that code but for the payload i still can’t read it .
image

what should i do next ? is there something missing ?

Check that the device is reading the correct device profile.

Also check that the device is sending the actual measurement and not some “keep alive” payload.

also, can you place the whole payload in here so I can have a look?

There is also another version of the codec in the device docs page, so also try the other one and see if that makes a difference.

yes i see there is 2 versions , i will try the other one .

As for the device profile , i’m sure i am using the right one .
this is the whole payload .

It works fine with the other code .
Thank you so much for your help

Can anyone help regarding how to decode payload in original form !