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;
A sample payload - either as bytes or the frm_payload field - will help with testing.
The decoder has only two major flaws:
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.
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.
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?
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