Decoding payload formatter help for MCF-LW06424

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

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.

Thanks, An example payload data is “0D01C0B26227470E001000100010”

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 :slight_smile:

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

Many thanks

Answered here:

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.

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.

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 :slight_smile:

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

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.