How to iterate over multiple tag topics?

I have multiple OPCUA tags emitting data. I want each of the tag to go through a series of steps (eg: add some property to the tag's payload, aggregate the data over 1 minute and finally write it to MongoDB using MongoDB out node). I have been able to do this successfully for one Tag. How do I do it for multiple tags? Datahub IN node or MQTT subscribe both allow only a single topic. What I need is to store each tag's topic in an array, iterate this array and for each topic, perform the afore mentioned flow.

Are the values for the individual topics arriving in separate messages? If so then can you not just feed each one through the flow to take whatever action is necessary?

If there are all in one message then can you show us the format of the data in a debug node so we can better understand.

I don't know what this point has got do do with your question, but an MQTT node can subscribe with wildcards so it can receive data for multiple topics.

If you're simply trying to collect a certain number of messages before processing, use the join node to gather them into an array of whatever length you want and then it will emit them for processing. Or, so the processing for each message as they arrive and then collect them for db insertion. OR, just send them to the db as they arrive, why batch them?

There are multiple tags, each having their own topic. So I cannot use DataHub connector in my flow, as it allows only one topic. Colin, if I understand it right, you are saying, I cannot use any flow node, to receive data from multiple topics as an array of messages?

Now about, MQTT. I have a SSL integration that subscribes to the above mentioned Tags. I was hoping that using MQTT In node in the Flow, I should be able to get all messages from all the above tags and then process them as needed with other nodes in the Flow. But that doesn't seem to work either. For the MQTT node, I am configuring the Data Topic of the SSL Integration as the TopicName. But it does not work.

Sorry, I dont know what you mean by tags or DataHub

That is also unclear. Do you mean multiple messages each with its own topic? If so, you can join data from multiple messages using a JOIN node. See this article in the cookbook for an example of how to join messages into one object.

Do you mean it subscribes to the topics?

What do you mean by SSL integration?

Again, that sentence does not mean anything to me.

Apologies, I must clarify that I am using Litmus IOT that provides Node Red to create flows within IOT edge devices. So the SSL and MQTT in my question comes from Litmus. I don't know if this is information is useful at all for Nodered forum to answer without knowing Litmus.
To generalize my question: Is it possible to dynamically pass a tag topic to a Flow or is it possible to pass an array of topics to a flow and perform some steps further down in the Flow for each of the messages from each topic in this array, and finally write the message to a Mongo DB?
NOTE: I have been successful in writing a single tag whose topic I know ahead of time, to Mongo using Mongo Out node. Now I am trying to do the same when tag's topic is dynamic, or from an array of topics.

You keep using the word tag, but that does not have any meaning in node red. What do you mean by a tag? Do you mean a message? But the answer is yes, you can pass anything anything you like into a flow in a message. Messages often have a topic value identifying the data source.

Yes, if you want to pass an array you can add a property to the message containing that, for example you could put it in msg.topicArray. you can call it anything you like.

It might be helpful to show us what the incoming data looks like (send it to a debug node) and explain exactly what you want to do with it.

Tag referred in my replies are OPCUA tags that produce boiler status information. An example message from one of the “tag” looks like this.
{"success":true,"datatype":"uint32","timestamp":1669011740925,"registerId":"3E44F469-207E-47DB-81CC-DBEBE4E0D6C9","value":829514,"deviceID":"5C406E38-BE06-49B8-9CB3-A32F85E39002","tagName":"Objects_OpcPlc_Telemetry_Fast_FastUInt3","deviceName":"OPCUAClient","description":"Constantly increasing value(s)","metadata":{}}

My flow configuration just for example (datahub subscribe + debug node) looks like this:
[{"id":"9bd219f5.79bc68","type":"Datahub Subscribe","z":"749e45e.2c8bebc","name":"telemetry-fast","natc":"882284f3.670668","topicname":"devicehub.alias.OPCUAClient.Objects_OpcPlc_Telemetry_Fast_FastUInt3","x":290,"y":120,"wires":[["79268265.2c1c9c"]]},{"id":"79268265.2c1c9c","type":"debug","z":"749e45e.2c8bebc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":530,"y":160,"wires":[]},{"id":"882284f3.670668","type":"Datahub Connect","ipadd":"","port":"4222"}]

Just like how the tag name here is Objects_OpcPlc_Telemetry_Fast_FastUInt3, there can be many such tags with different names for the given device each having their own topic. So as the user “subscribes” for each of this tag’s topic (through my app), there must be a way to pass the tag’s topic to the flow dynamically.

OK, now we have some clarity. When you talk about tags you mean messages containing data for a tag, where the tag id is in msg.payload.tagName.

Do you mean you want to dynamically configure an MQTT In node to subscribe to a particular topic?

If so then you can do that via dynamic subscription as described in the help text for the MQTT node. This post gives examples of how to use it Dynamic MQTT node's "actions->connect" guidance needed

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.