# COAP response changing HEX buffer

**URL:** https://discourse.nodered.org/t/coap-response-changing-hex-buffer/78443
**Category:** General
**Created:** [15 May 2023 18:01 UTC](https://discourse.nodered.org/t/coap-response-changing-hex-buffer/78443 "2023-05-15T18:01:16Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![JohnnyPicnic](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/johnnypicnic/32/34787_2.png) [@JohnnyPicnic](https://discourse.nodered.org/u/JohnnyPicnic)
#### Post date: [15 May 2023 18:01 UTC](https://discourse.nodered.org/t/coap-response-changing-hex-buffer/78443/1 "2023-05-15T18:01:16Z")

</div>

Hi All, I'm tying to respond to a COAP request with a buffer of:

```auto
[64,219,228,137,163,6]

```

```auto
String: 4090e589a306

```

The COAP response is coming out as:

```auto
[64,239,191,189,229,137,163,6]

```

```auto
String: 40efbfbde589a306

```

I've tried different encoding formats and using the buffer maker but can't seem to figure out why it's changing.

---

<div class="post-metadata">

### Author: ![JohnnyPicnic](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/johnnypicnic/32/34787_2.png) [@JohnnyPicnic](https://discourse.nodered.org/u/JohnnyPicnic)
#### Post date: [15 May 2023 18:52 UTC](https://discourse.nodered.org/t/coap-response-changing-hex-buffer/78443/2 "2023-05-15T18:52:02Z")

</div>

Some more info:  
If I set the response payload to `12345678`  
the request response comes out as `3132333435363738`  
or buffer

```auto
[49,50,51,52,53,54,55,56]

```

![2023-05-15_12-51-31](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/5/057686c57775c9cb482cccc145700addc9a8fe06.png)

---

<div class="post-metadata">

### Author: ![JohnnyPicnic](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/johnnypicnic/32/34787_2.png) [@JohnnyPicnic](https://discourse.nodered.org/u/JohnnyPicnic)
#### Post date: [17 May 2023 12:54 UTC](https://discourse.nodered.org/t/coap-response-changing-hex-buffer/78443/3 "2023-05-17T12:54:17Z")

</div>

I ended up finding an issue in node-red-contrib-coap where the content format is being set to one of three options and none of them allow just an unchanged payload to pass through.  
My quick and dirty fix was to set text/plain to msg.payload

```auto
if (_checkContentFormat(contentFormat, "text/plain")) {
            return msg.payload.toString();
        } else if (_checkContentFormat(contentFormat, "json")) {
            return JSON.stringify(msg.payload);
        } else if (_checkContentFormat(contentFormat, "cbor")) {
            return cbor.encode(msg.payload);
        } else {
            return msg.payload.toString();
        }

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [31 May 2023 12:55 UTC](https://discourse.nodered.org/t/coap-response-changing-hex-buffer/78443/4 "2023-05-31T12:55:09Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
