# HTTP integration fails, wrong raw data

**URL:** <https://www.thethingsnetwork.org/forum/t/http-integration-fails-wrong-raw-data/37809>\
**Category:** How to get started\
**Created:** [June 15, 2020, 6:18pm UTC](https://www.thethingsnetwork.org/forum/t/http-integration-fails-wrong-raw-data/37809 "2020-06-15T18:18:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jerrymek](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/jerrymek/32/33083_2.png) [@jerrymek](https://www.thethingsnetwork.org/forum/u/jerrymek)\
**Post date:** [June 15, 2020, 6:18pm UTC](https://www.thethingsnetwork.org/forum/t/http-integration-fails-wrong-raw-data/37809/1 "2020-06-15T18:18:55Z")

</div>

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:  
 ![image](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/7/5/7554605e17086a9b9c7b3d04e00ca39100df72ec.png)

Now I try to setup a HTTP integration to the request.bin but the raw data received does not match up:  
 ![image](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/f/e/fe4c31248e8768d70c8fae73cae79068b0a4e7c9.png)  
 ![image](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/9/4/9469c82e2f626ddb706c6e6cb16167dcc3a1edcd.png)

Any suggestions what can have gone wrong?

Thanks!  
Jerker

---

<div class="post-metadata">

**Author:** ![jeromeskiply](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/jeromeskiply/32/32659_2.png) [@jeromeskiply](https://www.thethingsnetwork.org/forum/u/jeromeskiply)\
**Post date:** [June 15, 2020, 7:14pm UTC](https://www.thethingsnetwork.org/forum/t/http-integration-fails-wrong-raw-data/37809/2 "2020-06-15T19:14:57Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![jerrymek](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/jerrymek/32/33083_2.png) [@jerrymek](https://www.thethingsnetwork.org/forum/u/jerrymek)\
**Post date:** [June 15, 2020, 7:16pm UTC](https://www.thethingsnetwork.org/forum/t/http-integration-fails-wrong-raw-data/37809/3 "2020-06-15T19:16:21Z")

</div>

Thx Jerome!

---

<div class="post-metadata">

**Author:** ![jeromeskiply](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/jeromeskiply/32/32659_2.png) [@jeromeskiply](https://www.thethingsnetwork.org/forum/u/jeromeskiply)\
**Post date:** [June 15, 2020, 7:20pm UTC](https://www.thethingsnetwork.org/forum/t/http-integration-fails-wrong-raw-data/37809/4 "2020-06-15T19:20:28Z")

</div>

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

```javascript
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)

---

<div class="post-metadata">

**Author:** ![jerrymek](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/jerrymek/32/33083_2.png) [@jerrymek](https://www.thethingsnetwork.org/forum/u/jerrymek)\
**Post date:** [June 15, 2020, 7:27pm UTC](https://www.thethingsnetwork.org/forum/t/http-integration-fails-wrong-raw-data/37809/5 "2020-06-15T19:27:30Z")

</div>

Thx again, that looks interresting!

---

<div class="post-metadata">

**Author:** ![jeromeskiply](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/jeromeskiply/32/32659_2.png) [@jeromeskiply](https://www.thethingsnetwork.org/forum/u/jeromeskiply)\
**Post date:** [June 15, 2020, 7:29pm UTC](https://www.thethingsnetwork.org/forum/t/http-integration-fails-wrong-raw-data/37809/6 "2020-06-15T19:29:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![arjanvanb](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/arjanvanb/32/46626_2.png) [@arjanvanb](https://www.thethingsnetwork.org/forum/u/arjanvanb)\
**Post date:** [June 16, 2020, 12:15pm UTC](https://www.thethingsnetwork.org/forum/t/http-integration-fails-wrong-raw-data/37809/7 "2020-06-16T12:15:31Z")

</div>

See also [Advantage of Base64 encoding in MQTT?](https://www.thethingsnetwork.org/forum/t/advantage-of-base64-encoding-in-mqtt/3425)

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](https://www.thethingsnetwork.org/forum/t/my-applications-downlink-is-always-queued-for-next-uplink/7014) (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:

> [@jeromeskiply](#):
>
> ```javascript
> var hexPayload = "";
> bytes.forEach(function(byte) {
> hexPayload += ('0' + (byte & 0xFF).toString(16)).slice(-2);
> });
> 
> ```

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](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce):

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

```

Enjoy. 😉
