Hello all, I am trying to receive data from plc and send it to influxDB. I am currently using switch node and change node to transform data into influx dB data type. This is my flow
I currently named the variables according to three fields and switch them to different routes
Then I used format nodes to convert the input data into fields and tags.
same for counterreject. For sap in the third route, I have added it as a field.
Now my output looks like.
22/11/2022, 09:57:19node: debug 15Cognex2 : msg.payload : array
22/11/2022, 09:57:19node: debug 15SAP_NUMBER : msg.payload : Object
This is what I am having now.
What I want: I would like to add the sap which I am receiving as tag for all the counters and rejects similar to line and machine. Is there a way we could do this?
It isn't entirely clear what it is that you are not able to do. Do you mean that the sap value arrives in a different message, so you can't just move it into the tags array? If so then how do you know which incoming data it has to apply to?
If that isn't it then please explain in more detail. Remember we know nothing about the data coming from your PLC.
Hello @Colin, Thanks for replying back . Yes, what you understood is right. I want to apply that sap as a tag to all the counters and rejects. For you to understand about the data , I'm trying to visualise the counters and rejects from different sensors in the line. sap number is the number which is given for a particular order . so I'm trying to connect it to the the counter values. Let me know if you still want to know any details.
You could save the sap number to flow context and pick it up when needed. You didn't answer the question about how you know which other messages the sap is linked to. Presumably you have to handle different sap numbers over a period. Is the message with the sap guaranteed to be the first number in a set of values for example?
The sap message is directly linked to the influxdb out node. The sap number keeps on changing over a period of time. Apologise me, I think I don't understand your question properly. Can you explain it again?
Perhaps I misunderstand what you want. I thought you wanted to include the sap value in with the data that you previously posted
22/11/2022, 09:57:19[node: debug 15](http://10.177.28.10/node-red/#)Cognex2 : msg.payload : array
So you want the sap value added after the machine value in the tags. If that is correct then the influx node cannot do that automatically, so you need to have the sap available when you build the payload with the rest of the data.
If that is correct then a fundamental question is where does the sap come from? Does it come from the PLC? If so then ideally you would get all the data in one go from the PLC rather than have it come in by separate messages. The reason is that as you have it at the moment you have to join the sap value in with the other data before writing it to influx, which means saving it somewhere and then picking it up again, and you have the problem of making sure that the sap value you use is the correct one for the rest of the data. What type is that plc node?
Apologise me for responding late. The sap comes from the PLC too. Th problem is when I try to get the sap from the same node. The sap value is being stored in the field counterIN as my configuration in the format node is such as that.
Because I am receiving all variables one per message from the plc node. The plc node is s7 in node(siemens plc).
Is it possible to get all the variables at once? That would make this much easier.
Yes it is possible to receive all variables at once, But when I do that, there is only one message and With which I can create a lot of fields with unique payload values but in the change node, It is not possible for me to create tags for each machine with unique msg.topics . What do you suggest which you say could be easy? Is there a other way which s possible ?
Do it with all the values in a single message. Show us what the data coming looks like. I don't understand exactly what the problem is.
This is when I pass all the variables in the node as ALL variables one per message
This is when I pass all the variables in the node as ALL variables
You have not said what is wrong with that. Is it that you have not separated out the fields and tags? If so, then if you look at the help text for the influx node it defines how to format the data for that. You need to send an array of two objects, the first is the fields and the second is the tags. So you need something like
I am using the format node to convert it into influxDB format and When I pass all variables in one message, I get unique payloads i.e msg.payload for each variable but I don't see it working it with the msg.topic.
I can copy the path of a variable payload like msg.payload["2D-CONTROLE LCOUNTER"]
But I cannot do the same with the msg.topic["2D-CONTROLE LCOUNTER"]
and I'm using format node to transform the data where I am not able to mention this msg.topic should be this tag(machine). What I understand from your reply is you need create a function and do this, can you format this for each variable and specify tags and fields for each variable separately?
PLEASE HELP ME UNDERSTAND!
I don't know the Format node. Which node is that?
Show us the data going into it and how you have configured it.
Sorry I said the format node, It is actually change which I named as format in my flow. As you see in the flow, The data is switched to three routes for three fields, counterIN, counterREJECT and sap This is the data going into it the CounterIN change node
And it is configured into this in change node
I can't read those screenshots. Please configure an Inject node with the data going into the change node (You can use the Copy button as described in the canned reply below to copy it into an Inject node configured to generate JSON) and feed that into the change node. Check that it isn't doing what you want then Export those two nodes here so we can see more clearly what is going on.
See this page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path to any data item.
Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.