How to read node properties on deployment

I have an idea for a node and successfully prototyped it using existing primitives. I have a data source that required I subscribe to specific parameters. I send a single JSON message to the server containing a list of all the parameters I want to subscribe to. It then periodically sends a single JSON message containing updates for the various parameters. I can't subscribe to all the parameters since it could be hundreds of thousands of parameters in all. As it is, I'm manually building the subscription list in the Node Red editor. For prototyping purposes, I then add a debug node for each parameter and manually set the path within the JSON object to the parameter of interest. For example:

"subscriptions: [
{name, "param_abc"},
{name,"param_123"}
]

for the subscription list, and

"msg.payload.data.param_123.value"

for the node that picks out the value from the incoming JSON message. So the parameters are actually defined twice.

After studying the Node API, I can easily see how to write a "parameter selector" node that lets the user just set the parameter ID. The node would then find the parameter in the input JSON message, and output the value. No problem.

But I still have to add the parameter both to the node that parses the incoming message AND the subscription list. If I could just create a new node that, at startup, basically finds all my "parameter selector" nodes, reads the parameter ID, assembles the subscription message and sends it to the data source. Then the user just needs to set the parameter ID in the "parameter selector", and my new data provider node would automatically subscribe to all the required parameters.

What would be the best way to do this? What is the best way for a node to iterate through all the nodes (either globally or within the flow), determine the specific node type, and read a property from it? All at initial deployment.

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