I am very new at Node-red but I am trying to create a dashboard for some of the modbus data of a syste. However, I am having problems reading 32-bit floating point values (16-bit integers are ok). And I was hoping someone could help me with this.
The information I want to read is a the voltage of the system, and it is contained by two registers (209/210). I am using a very simple stetup to read the registers, convert them into a foat buffer and finally to a decimal value.
For getting the float buffer I am ussing the following code
var payload=msg.payload;
var buf = Buffer.alloc(4);
buf.writeFloatBE(payload);
msg.payload=buf;
return msg;
For getting the decimal valules (found in one of the forum topics):
let pay = msg.payload;
const buf = Buffer.allocUnsafe(4); // (4) is ok
buf.writeUInt16BE(pay[0]); // high byte
msg.payload = buf.readFloatBE(0);
// 2 numbers after comma (string)
msg.payload = buf.readFloatBE(0).toFixed(2);
//
return msg;
But the values I get are not ok. Could anyone help?
Thanks but i am afraid I still dont know how to use that node. I tried using it but I get either a syntax error "Unexpected token p in JSON at position 0" or a type error "Cannot read property 'resultType' of undefined". Do you have some examples how I should use it?
There are lots of examples in the built in sample...
CTRL+I > import > examples.
If you give me a copy of your data (the buffer data you are feeding in) and what you need out 9the formatted data out of buffer-parser) I'll knock up a simple example.
Share your flow (select the relevant nodes in your flow then press CTRL+E)
``` paste your flow between 3 backticks - like this ```
i was reading this topic because i'm looking for a hint to resolve a similar issue.
I'm using a Moxa ioLogik (1242) to read some AI (4-20mA). Moisture and Temperature. I can read scaling values and i received the following array [32870,16838,10199,16856], those values are 24,8 ppm and 27 °C aprox.
I 'don't understand how to use the buffer parser to convert [32870,16838] in 24,8 ppm and [10199,168566] in to 27 °C. I try with some examples that you refer, but i can't make it.
I did a demo with your data. The 1st buffer parser is set to return 1 object with your values in, the 2nd one is set to return individual results with the topic set (perfect for sending straight to MQTT)...
I deployed both buffer parser and are working good. In my aplicattion, the first parser work better than second (i'm connecting the node to Ubidots_out node).
An other thing i'm learned, it's about some concepts that i don't handle. For example, in the variable "ppm" the offset is 0, but in the variable "temp" is 4. Why?
So, the last favor i ask you if you know some repository where i can learn this concepts. Maybe are too simple, but i'm new in this world.
As your data is 4 x 16bit values, that equates to 8 bytes. Bytes 0~3 contains the value of ppm. Bytes 4~7 contain the value of temp.
That buffer parser node is designed to ease a common task (like this task you're facing). Behind the scenes, it interprets your specification & parses the data by a sprinkling of maths & the nodejs Buffer
There is no specific tutorials for this kind of thing. You kinda pick it up working with PLCs and various programming languages over the course of many years. For this particular solution, there are a few different technologies / disciplines converging here...
JavaScript / nodejs / nodejs buffers, Json, Computer science bits n bytes, Node-red.
You are probably best off starting here: Node-RED Essentials. It is by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in less than an hour.
Get to grips with node-red and pick up the coding when you need to get more adventurous.
Ps, read the built in help of a node in the sidebar in node-red. Normally all the info you need is in there.