# Decoding payload formatter help for MCF-LW06424

**URL:** <https://www.thethingsnetwork.org/forum/t/decoding-payload-formatter-help-for-mcf-lw06424/59170>\
**Category:** Uncategorized\
**Created:** [October 4, 2022, 2:46pm UTC](https://www.thethingsnetwork.org/forum/t/decoding-payload-formatter-help-for-mcf-lw06424/59170 "2022-10-04T14:46:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexkellyTBG](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/alexkellytbg/32/35697_2.png) [@alexkellyTBG](https://www.thethingsnetwork.org/forum/u/alexkellyTBG)\
**Post date:** [October 4, 2022, 2:46pm UTC](https://www.thethingsnetwork.org/forum/t/decoding-payload-formatter-help-for-mcf-lw06424/59170/1 "2022-10-04T14:46:16Z")

</div>

Hi,

I’ve setup MCF-LW06424 and its reading the data correctly when reading through the laptop through the USB cable but not when passed to the things network. Can anyone help me and see if im formatting the data correctly?

The left hand setup app shows a reading of 18.003ma (circled in red) which is correct. However the data on the right (circled in red) shows the formatted data from the things network via mqtt and it gives a value of 3585 which is incorrect. Here’s the script im using to format the data:

> function Decoder(bytes, port) {  
> // Decode an uplink message from a buffer  
> // (array) of bytes to an object of fields.  
> var decoded = {};  
> decoded.bytes = bytes;
> 
> ```
> // milliamps data
> if(bytes[0] == 0x0D) {
> var input1 = (bytes[7] << 8) | bytes[6];
> decoded.milliamps1 = input1 
>   
> var input2 = (bytes[9] << 8) | bytes[8];
> decoded.milliamps2 = input2 
>   
> var input3 = (bytes[11] << 8) | bytes[10];
> decoded.milliamps3 = input3 
>   
> var input4 = (bytes[13] << 8) | bytes[12];
> decoded.milliamps4 = input4 
> }
> return {
> data: {
> input1: decoded.milliamps1,
> input2: decoded.milliamps2,
> input3: decoded.milliamps2,
> input4: decoded.milliamps2 
> },
> warnings: [],
> errors: []
> 
> ```
> 
> };
> 
> }

Here’s the document from the supplier saying how the data should be formatted. Can anyone help me and see if im formatting the data correctly. [https://connectedthings.store/gb/index.php?controller=attachment&id\_attachment=52](https://connectedthings.store/gb/index.php?controller=attachment&id_attachment=52)

 ![image](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/8/5/859dc19479f63d5ad73293ff13d0f8916a51d6b3.jpeg)

---

<div class="post-metadata">

**Author:** ![descartes](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/descartes/32/47220_2.png) [@descartes](https://www.thethingsnetwork.org/forum/u/descartes)\
**Post date:** [October 4, 2022, 3:39pm UTC](https://www.thethingsnetwork.org/forum/t/decoding-payload-formatter-help-for-mcf-lw06424/59170/2 "2022-10-04T15:39:55Z")

</div>

A sample payload - either as bytes or the frm\_payload field - will help with testing.

The decoder has only two major flaws:

1. You create a variable to store a value and then use the same name for an object - whilst I doubt it actually breaks the JavaScript interpreter, it certainly breaks any human JS interpreter as a major distraction / clash of concepts - like fingernails down a chalk board.

2. You are treating each of the two-bytes as an integer value but the documentation says that only bits 0 to 11 are the value, other bits will be set as per docs.

---

<div class="post-metadata">

**Author:** ![alexkellyTBG](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/alexkellytbg/32/35697_2.png) [@alexkellyTBG](https://www.thethingsnetwork.org/forum/u/alexkellyTBG)\
**Post date:** [October 4, 2022, 4:15pm UTC](https://www.thethingsnetwork.org/forum/t/decoding-payload-formatter-help-for-mcf-lw06424/59170/3 "2022-10-04T16:15:54Z")

</div>

Thanks, An example payload data is “0D01C0B26227470E001000100010”

---

<div class="post-metadata">

**Author:** ![alexkellyTBG](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/alexkellytbg/32/35697_2.png) [@alexkellyTBG](https://www.thethingsnetwork.org/forum/u/alexkellyTBG)\
**Post date:** [October 5, 2022, 1:22pm UTC](https://www.thethingsnetwork.org/forum/t/decoding-payload-formatter-help-for-mcf-lw06424/59170/4 "2022-10-05T13:22:10Z")

</div>

Hello, I’ve got a bit further in my decoding journey. I’m new to the decoding part and not a expert in Java script so figuring this would as I am going along. Thanks for the help 🙂

I still don’t know why the figure reading from the app which is correct (on the left) is different to the transmitted MQTT reading which is incorrect (on the right).

The datasheet says bit 0 to 11 is to be rescaled. Is this the bit that im missing? i dont know how to rescale…any thoughts?

also the line below to collec the data, is it picking it up at the correct location?

> var input1 = (bytes[7] \<\< 8) | bytes[6];

![image](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/5/d/5da2e79016a5c6d5a2de07e6d7abc90df7d11c4e.png)

Many thanks

---

<div class="post-metadata">

**Author:** ![descartes](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/descartes/32/47220_2.png) [@descartes](https://www.thethingsnetwork.org/forum/u/descartes)\
**Post date:** [October 5, 2022, 3:20pm UTC](https://www.thethingsnetwork.org/forum/t/decoding-payload-formatter-help-for-mcf-lw06424/59170/5 "2022-10-05T15:20:42Z")

</div>

> [@alexkellyTBG](#):
>
> I still don’t know why the figure reading from the app which is correct (on the left) is different to the transmitted MQTT reading which is incorrect (on the right).

Answered here:

> [@descartes](#):
>
> You are treating each of the two-bytes as an integer value but the documentation says that only bits 0 to 11 are the value, other bits will be set as per docs.

For scaling, you are reading a channel that does 4-20mA - once you have the reading, free of any additional flags in the integer, you should be able to figure out the ratio for the 16mA that it runs across.

> [@alexkellyTBG](#):
>
> also the line below to collec the data, is it picking it up at the correct location?

It looks like the first channel would be from the byte after the Uplink ID, Type and Timestamp as written - I suspect if you figure out the array positions of those, you’ll have your answer.

---

<div class="post-metadata">

**Author:** ![alexkellyTBG](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/alexkellytbg/32/35697_2.png) [@alexkellyTBG](https://www.thethingsnetwork.org/forum/u/alexkellyTBG)\
**Post date:** [October 6, 2022, 3:57pm UTC](https://www.thethingsnetwork.org/forum/t/decoding-payload-formatter-help-for-mcf-lw06424/59170/6 "2022-10-06T15:57:29Z")

</div>

Thanks I figured it out from what you said. I wasn’t expecting it to send the discrete values, i was expecting the ma. After that it all made sense and the calculations worked out. Many thanks 🙂

---

<div class="post-metadata">

**Author:** ![descartes](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/descartes/32/47220_2.png) [@descartes](https://www.thethingsnetwork.org/forum/u/descartes)\
**Post date:** [October 6, 2022, 4:13pm UTC](https://www.thethingsnetwork.org/forum/t/decoding-payload-formatter-help-for-mcf-lw06424/59170/7 "2022-10-06T16:13:52Z")

</div>

This is the community forum, we’d ask that you share your output for others to enjoy at a later date please.

---

<div class="post-metadata">

**Author:** ![francozampicinini](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/francozampicinini/32/45735_2.png) [@francozampicinini](https://www.thethingsnetwork.org/forum/u/francozampicinini)\
**Post date:** [May 17, 2023, 9:16am UTC](https://www.thethingsnetwork.org/forum/t/decoding-payload-formatter-help-for-mcf-lw06424/59170/8 "2023-05-17T09:16:07Z")

</div>

Only to be clear:

3585 is the value of bits (on a scale from 0 to 4095) on a range of 4 to 20mA (so 16mA span).

3585/4095\*16mA + 4mA = 18.007mA

Hope this can help.
