# How to decode CBOR in a payload format Decoder?

**URL:** <https://www.thethingsnetwork.org/forum/t/how-to-decode-cbor-in-a-payload-format-decoder/36373>\
**Category:** Application Development\
**Created:** [April 21, 2020, 7:09pm UTC](https://www.thethingsnetwork.org/forum/t/how-to-decode-cbor-in-a-payload-format-decoder/36373 "2020-04-21T19:09:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaniaSoto](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/daniasoto/32/25844_2.png) [@DaniaSoto](https://www.thethingsnetwork.org/forum/u/DaniaSoto)\
**Post date:** [April 21, 2020, 7:09pm UTC](https://www.thethingsnetwork.org/forum/t/how-to-decode-cbor-in-a-payload-format-decoder/36373/1 "2020-04-21T19:09:41Z")

</div>

Hello,  
I’m using the example [enviromental sensing of AllThingsTalk](https://docs.allthingstalk.com/examples/kits/lorawan-rdk/sodaq-mbili-environmental-sensing/) that sends different sensor values using cbor.  
The problem is that I would like to send those values to another platform using the integration Data Storage instead of AllThingsTalk, and it seems that I’ll have to write a decoder .  
The sending data of, for example, the temperature value is 35 FA 41 AF 85 1F 62 where 35 is sensorID and FA 41 AF 85 1F 62 the value, that is 21.94 according to [cbor decoder](http://cbor.me/).  
I’ve seen some decoders from byte to float of 32 bits but here I have 48 (FA 41 AF 85 1F 62) ¿Is it posible to decode 48 bits instead of 32?

---

<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:** [April 22, 2020, 8:29am UTC](https://www.thethingsnetwork.org/forum/t/how-to-decode-cbor-in-a-payload-format-decoder/36373/2 "2020-04-22T08:29:01Z")

</div>

I cannot get your example to decode in the decoder. But it’s not always going to be 48 bits, but depends on the actual value:

> [@Sending "cooked" JSON data to AllThingsTalk](https://www.thethingsnetwork.org/forum/t/sending-cooked-json-data-to-allthingstalk/31470/3):
>
> But even the binary CBOR just requires too many bytes for just a simple value. Like in this example:
> 
> > In RDK example, your temperature sensor reads 23 degrees Celsius, and you’d like to see that value in Maker. You can use [cbor.me](http://cbor.me/) to convert the payload to CBOR, e.g,
> > 
> > `{"temperature": 23}` translates to `A1 6B 74 65 6D 70 65 72 61 74 75 72 65 17`
> 
> While the plain text `{"temperature": 23}` would be 19 bytes, the above CBOR’d version is still 14 bytes for a single _integer_ value!
> 
> Even when using `{"t": 23}`, you’d still get 4 bytes for `A1 61 74 17`. A fixed position encoding, with an unrealistic temperature accuracy of 2 decimals, would allow for -327.68 thru 327.67 in just 2 bytes.
> 
> Adding a decimal in CBOR, `{"t": 23.5}` yields 6 bytes in `A1 61 74 F9 4D E0`. But other values might go crazy, like `{"t": 23.4}` yields the whopping `A1 61 74 FB 40 37 66 66 66 66 66 66`. Play around with [http://cbor.me/](http://cbor.me/) before considering using CBOR.

So, even when not using JSON, I’d fix the problem at its root cause, and try to get rid of CBOR. Unless your device sends a lot of different types of messages, it’s just too much overhead to use in LoRaWAN. And even if it does send a lot of different messages, then see, e.g., [Multiple sensors with different payload decoding TTN](https://www.thethingsnetwork.org/forum/t/multiple-sensors-with-different-payload-decoding-ttn/30351) and [How to best write an application that contains many nodes with different measure data types](https://www.thethingsnetwork.org/forum/t/how-to-best-write-an-application-that-contains-many-nodes-with-different-measure-data-types/6916).

If you really cannot get rid of it, then you’ll need to copy a CBOR helper into the payload format in TTN Console, and use that helper in the Decoder function. See [Implementations on the CBOR website](http://cbor.io/impls.html).

---

<div class="post-metadata">

**Author:** ![DaniaSoto](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/daniasoto/32/25844_2.png) [@DaniaSoto](https://www.thethingsnetwork.org/forum/u/DaniaSoto)\
**Post date:** [April 22, 2020, 9:31am UTC](https://www.thethingsnetwork.org/forum/t/how-to-decode-cbor-in-a-payload-format-decoder/36373/3 "2020-04-22T09:31:41Z")

</div>

Thanks for your answer, I’ll try to get rid of CBOR.
