Extract Buffer Data

92 views
Skip to first unread message

Mellow Pepper

unread,
Jul 22, 2017, 11:43:44 PM7/22/17
to Node-RED
Having the Modbus Response below how would I extract out each value to a usable form?


I need to be to send to a dashboard and create a json data stream

Any help is awesome

Thank you.
Auto Generated Inline Image 1
Auto Generated Inline Image 2

steve rickus

unread,
Jul 24, 2017, 9:09:35 AM7/24/17
to Node-RED
It appears that you already have a JSON structure -- from the attached image, I can see that msg.payload is a single javascript object with 2 fields: "data" and "buffer". It looks like each field holds information from the same 20 bytes of modbus register data. So msg.payload.buffer is a javascript buffer of those 20 bytes, and msg.payload.data is an array of the equivalent 10 integers, taken 2-bytes at a time. But only you can know what is being stored in those registers, or what the numbers mean.

If you are having trouble accessing individual elements of the JSON structure, it may help to read the tutorials about javascript objects and arrays on the W3Schools site -- I use it all the time to find the javascript functions I need to manipulate my data.

If the registers should be holding measurements that are floating point numbers, you can process the buffer values into numbers using the node-red-contrib-binary node (although to be honest, I have not figured out the packet syntax to make this node work). Another option is to use a function node and create a view of the buffer as 4- or 8-byte floats, using the DataView functions built-in to javascript. If you are still stuck, please let us know what data the registers hold, in what order and byte sizes, and any expected values for those fields.
--
Steve
Reply all
Reply to author
Forward
0 new messages