I need to know what was in the payload before the function call (what came out of the modbus node) and after.
I need to know what was in the payload before the function call (what came out of the modbus node) and after.
@megha.vaswan What @philip just commented on is really really important and critical advice for working in Node-RED.
It took me a long time to get used to the habit of putting a debug node on BOTH sides of any function blocks that I was having trouble with.
You MUST look at what is going INTO the function node as well as what is coming OUT of the node.
And both debug nodes must be set for complete msg object
Also, what is the expected result? The results you posted all look like good floating point numbers which makes me think the logic is working correctly and maybe there is a problem elsewhere (the sensor itself or the register address is incorrect).
Here is a jsfiddle with the conversion logic if you want to run some testing:
Below was the msg.payload output before the function call.
Below is the msg.payload after the function call.
The expected output is to display the room temperature value on node red debug window like 24.1 so on.
The actual register is 1 and 2 where temperature value will be store , however for node-red-contribute-modbus will start the register address from , so I did (Address -1).
Thanks
Ahhh, error in the conversion logic, change the second setUInt16 to
view.setUint16(2, msg.payload[0]);
Thanks @philip with code I have the correct temperature on node red debug window. However the code is same only except one line changes which as follows
view.setUint16(2, msg.payload[0]); Here instead of 1 as a argument you have changed to 2.
I am unable to understand, Can you please provide one line explanation ?
The first parameter is the byte offset of the buffer. The first UInt16 is 2 bytes so it occupies byte 0 and 1, so the second UInt16 needs to start at byte 2.