# MQTT topic: CBOR conversion

**URL:** https://discourse.nodered.org/t/mqtt-topic-cbor-conversion/29151
**Category:** General
**Created:** [29 June 2020 08:55 UTC](https://discourse.nodered.org/t/mqtt-topic-cbor-conversion/29151 "2020-06-29T08:55:41Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![kalpino](https://avatars.discourse-cdn.com/v4/letter/k/97f17d/32.png) [@kalpino](https://discourse.nodered.org/u/kalpino)
#### Post date: [29 June 2020 08:55 UTC](https://discourse.nodered.org/t/mqtt-topic-cbor-conversion/29151/1 "2020-06-29T08:55:41Z")

</div>

Hello,  
I have a topic that publishes data in CBOR format. I installed the CBOR block so that I can convert data from CBOR to JSON.  
When I try to show the converted message in the debug panel, I always get an empty message.  
Where am I going wrong?

Here is the nodes I'm using.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/6/a669eb24e37fce4d087fc7af2b177300b632ebc2.png)  
Thanks

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [29 June 2020 09:10 UTC](https://discourse.nodered.org/t/mqtt-topic-cbor-conversion/29151/2 "2020-06-29T09:10:52Z")

</div>

I don't know if anyone here has any experience of the CBOR node, so I doubt you'll get a direct answer.

But we can help you try to figure it out.

I assume you mean `node-red-contrib-cbor` - it is barely complete node, with no help text.

Looking at its code, I can see it will only decode `msg.payload` if it's a Buffer type object. So the question what is the MQTT node passing it. You can configure the MQTT node to always send a Buffer type object - I suggest you do that it you haven't already. It's always worth adding a Debug node so you can check exactly what you are passing into the CBOR node.

---

<div class="post-metadata">

### Author: ![kalpino](https://avatars.discourse-cdn.com/v4/letter/k/97f17d/32.png) [@kalpino](https://discourse.nodered.org/u/kalpino)
#### Post date: [29 June 2020 09:14 UTC](https://discourse.nodered.org/t/mqtt-topic-cbor-conversion/29151/3 "2020-06-29T09:14:15Z")

</div>

I already have the MQTT block passing a buffer. Also, using a debug node I can see that the output of the mqtt block is an array of cbor-encoded data.  
What I expect as an output of the CBOR node is data in JSON format but all I get is an empty payload.

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [29 June 2020 09:17 UTC](https://discourse.nodered.org/t/mqtt-topic-cbor-conversion/29151/4 "2020-06-29T09:17:55Z")

</div>

Given how little code is in the node ([https://github.com/DoNck/node-red-contrib-cbor/blob/master/node-red-contrib-cbor.js](https://github.com/DoNck/node-red-contrib-cbor/blob/master/node-red-contrib-cbor.js)), there's not much I can see to go wrong, assuming its using the `cbor` library properly.

At this point, you'd need to raise an issue against the node so its author can provide some assistance - [https://github.com/DoNck/node-red-contrib-cbor/issues](https://github.com/DoNck/node-red-contrib-cbor/issues)

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [29 June 2020 09:25 UTC](https://discourse.nodered.org/t/mqtt-topic-cbor-conversion/29151/5 "2020-06-29T09:25:31Z")

</div>

If it is already a buffer then I'm not sure why they need to do this  
`msg.payload=cb.decode(new Buffer(msg.payload));`  
[https://github.com/DoNck/node-red-contrib-cbor/blob/master/node-red-contrib-cbor.js#L12](https://github.com/DoNck/node-red-contrib-cbor/blob/master/node-red-contrib-cbor.js#L12) .

Also there are some limit on object size on the underlying library - [https://www.npmjs.com/package/cbor](https://www.npmjs.com/package/cbor) - so how big is the object you are trying to decode ?

Certainly a simple object -\> cbor -\> object seems to work ok. but maybe there are extra encodings in the cbor buffer you have ? see [https://github.com/hildjj/node-cbor#supported-types](https://github.com/hildjj/node-cbor#supported-types)

---

<div class="post-metadata">

### Author: ![kalpino](https://avatars.discourse-cdn.com/v4/letter/k/97f17d/32.png) [@kalpino](https://discourse.nodered.org/u/kalpino)
#### Post date: [29 June 2020 10:06 UTC](https://discourse.nodered.org/t/mqtt-topic-cbor-conversion/29151/6 "2020-06-29T10:06:07Z")

</div>

The CBOR block works fine. My problem is probably due to the fact that CBOR encoded data in input to the block were not encoded from a JSON but from an array of data.  
I will probably have to change the block so that it can decode data that is not in JSON format.  
Thanks!

---

<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: [13 July 2020 10:06 UTC](https://discourse.nodered.org/t/mqtt-topic-cbor-conversion/29151/7 "2020-07-13T10:06:07Z")

</div>

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