Node and MySQL data logging

Dear Friends,
we are trying to connect PLC with MySQL Database.
we could able to connect PLC and read the current value of the memory address.
To read each tags, using individual nodes but requirement is to introduce function node between Read node and MySQL and write the insert command on the same.
Please help.
Kindly refer the following Image with Node and Table structure

messages are async and NEVER arrive at the same time. So your function will run 5 (different times). This is key to understanding node-red.

What you can do is use a join node to group the 5 reads into one key/val object.

However, your design is inefficient.

Multiple reads from PLC can result in inconsistent data and is 5x slower than reading 1 LOT of data in one go.

If you decide to do this the "better way" my suggestion is to read all values in one go & use something like the buffer-parser node to arrange the collected array of data into nice typed values, ready for insert into the database.

In order to get all the data into the function node at the same time, you need to use a join node. I suggest you read the documentation "Working with messages" and pay attention to the section on "Message sequences".

After that, if you still have questions, please ask them and show us what you have tried.

Can you read all of the data in one fetch from the plc? If so do that, then you will have it all in one message.

Thanks a lot. Let me try with JOIN Node

Yes. I can read all tags in one message.

Dear Steve,
Thanks for your swift reply and suggestion.
I shall try with JOIN node.
Regarding consistent reading and storing the data to table, will it be ok if we use different tables ? or any other database you suggest ?

Thanks again

Depends on the driver. I didn't write this one but if I were to guess, no, reading from different PLC areas is possibly achieved by separate transmissions (therefore not consistent). But I am speculating based on experience.

To pretty much guarantee consistency of data you should aim for contiguous data memory address. Even if that means moving the various values in the PLC into another contiguous "collection" area.

After a stretch and a coffee and a reread, I will try again :smiley: ...

If you read data in a consistent manner from the PLC, you can write it to 1 or 2 or X tables in 1 or 2 or X databases without issue. Basically, once the data is captured, PLC scan is no longer a consideration.

Thanks steve.

If you can read them all at once then do that, and then you don't need to use the Join node to put them back together. That will be more efficient both in the PLC and in node-red.