0
votes

How can a configuration node be accessed (for read and write) or even be created inside a function node?

My scenario: I have a ModbusTCP node that uses configuration nodes for host/port settings. I need to create different configuration nodes inside my flow.

2

2 Answers

1
votes

You can not (normally) create (config or otherwise) nodes from with in a flow.

And you definitely can not directly edit existing nodes from with in the flow.

I say normally, because if you REALLY REALLY need to you can use the admin api to fetch the flow as JSON, edit it and then redeploy the whole flow.

But this is a multi stage process

0
votes

Generally you would define a config node as part of your package and provide a property on your main node to link to it. You could then have lots of different config nodes configured with different values. In general, I would probably have preferred having properties on the main node if it varies for all of them and just have the shared stuff like credentials, server address etc in a common config node. All nodes can have whatever properties you would like and they can be set in the UI. Properties on nodes: https://nodered.org/docs/creating-nodes/properties defining a config node: https://nodered.org/docs/creating-nodes/config-nodes

You access your config from the config parameter sent to the node when loaded

function komfoventNode (config) {
    RED.nodes.createNode(this, config);
    this.komfoUser = RED.nodes.getNode(config.user);

The komfoventNode has a property defined as user, which points to my komfoventConfig node.

defaults: {
            displayNname: {value:""},
            user: {value:"",type:"komfoventConfig", required:true}
        }