Payload decoder Javascript

Hello everyone,

I receive some data from my sensor :
image
This is the payload that I’m expected, but when I’m checking in “Event” at data it shows me this :
image
Which for me is an issue because when I put some java to decode the payload I get something like this :
image

My goal is to send those data to InfluxDB, so first I need to decode this payload image, but I can’t If I’m not able to retrieve the data into a variable.

Thank you very much!

Sounds like you’re decoding it wrong. The data field in the uplink is shown in Base64 encoding, you’ll want to do a base64 to hex conversion.
If you paste your data into here: https://cryptii.com/pipes/base64-to-hex you get your expected bytes in hex.

1 Like

Hi Ritch, It sounds to me that you are missing one conversion.

You should receive data in base64, transform it to hex and, finally, from hex to ascii.

I needed to do this conversion to use THINGSBOARD http integration (so that Thingsboard can “read” the data properly).

PS: You should also “split” or “parse” the data in the correct bytes.

I have some guides here.
You need to convert from hex/base64 to json or human readable ascii

1 Like

I find the issue of my problem, yes.

function decodeUplink(input)
{
  return{
    data: Decode(input.fPort, input.bytes, input.variables)
  };
}

function Decode(fPort, bytes, variables) {
  
  var data ={"Temp1":"",
             "Temp2":"",
             "battery":"",
             "bytes":""};
  data.battery= bytes[1] & 0x0002;
  data.Temp1= (bytes[3] + bytes[2])/10;
  data.Temp2= (bytes[5] + bytes[4])/10;
  data.bytes= bytes;
  
  return data;
}

This is the code that I used to decode the payload of an Adeunis Temp sensor :slight_smile:

1 Like

Thanks for sharing!

May be useful for someone