HTTP integration fails, wrong raw data

I’ve set up one LoRa Gateway and one Lora Node and an Application. Once every quarter I send 3 bytes of data from the node.
The debug printouts from the node shows for example:
18:54:25.816 -> 1c1c01
19:09:26.744 -> 1c1c01
19:24:27.675 -> 1c1c01
19:39:28.632 -> 1c1c01
19:54:29.560 -> 1c1c01
20:09:30.467 -> 1c1c01
And I can verify the correct transfer in the data tab of the Application:

Now I try to setup a HTTP integration to the request.bin but the raw data received does not match up:

Any suggestions what can have gone wrong?


Hi Jerker,
payload_raw is the base64 encoded payload.
So you have to decode it to be able to find your hex data back (hexadecimal is just a way to represent binary data).

1 Like

Thx Jerome!

You can also generate a “hex_payload” key inside TTN with this kind of function (to be adapted to your payload):

function Decoder(bytes, port) {
  var hexPayload = "";
  bytes.forEach(function(byte) {
    hexPayload += ('0' + (byte & 0xFF).toString(16)).slice(-2);
  var decoded = {hex_payload:hexPayload};
  return decoded;

(In Payload format / decoder / custom)

Thx again, that looks interresting!

1 Like

Last information: if you use this function, the hex_payload key will be included in the payload_fields object when you will push data to your endpoint.

See also Advantage of Base64 encoding in MQTT?

Just a minor note: if one is really only using the Decoder to get a hexadecimal text representation of the binary payload, then note that even that will take a bit of time. That’s probably not a problem, unless, e.g., one schedules a downlink using the HTTP Integration, where timing is really tight. See My application's downlink is always queued for next uplink (though not using a Decoder may not fix that).

I’d convert the Base64 representation in my application instead, if only to keep all code in one place.

And another aside:

In the Decoder, the values in the bytes array will never exceed 0xFF. So, byte.toString(16) would suffice. And in case one wants to avoid the loop and mutable variables, Array.reduce is your friend:

function Decoder(bytes, port) {
  return {
    hex_payload: bytes.reduce(function(acc, byte) {
      return acc + ('0' + byte.toString(16)).slice(-2);
    }, '')

Enjoy. :wink: