Parametric subflows? Or Dynamic serial port?

Just wondering if subflows can be made parametric in some way.
I am developing a flow that can be saved as subflow to be used from other flows, but...
Inside this subflow there is a serial port request node that should be pointed to a different serial port for each istance (maybe with the parent flow passing the serial port to use).
Or seeing it from another point of view, is it possible to have a dynamically configured serial port node?
Has anyone a clue or a suggestion, please?
Advanced thanks

Subflows can have env variables and most nodes can use env variables so the quick answer is probably. The longer answer depends on which properties you want to parameterise.

Just the serial port to which the serial port node is due to connect to

See Subflows : Node-RED for how to use subflow properties so each instance of the subflow could specify a different port.

Ok, if I understood correctly I can define the env variable in the subflow istance and use it into the nodes.
It is then a static configuration that I need to make beforehand.
It is not a variable that can be passed dynamically from the parent flow, right?

Correct.
You could pass in dynamic data via message properties, but that cannot be used to specify the serial port, as the node does not allow dynamic assignment.

Thank you Steve-Mcl and Colin, I will give it a try and report here.
Much appreciated :smiley:

I checked and Colin is right if I define an env variable

serport = /dev/ttyUSB0

and use it into the serial node

$env{serport}:115200-8N1

I receive the error

"[serialconfig:33a190bb5f257765] serial port $env{serport} error: Error: Error: No such file or directory, cannot open $env{serport}"

it was worth a try :cry:

Show us exactly what you entered & where.

Also, check what you have done with the docs: Using environment variables : Node-RED

Note. When Colin states

That does not mean env vars cannot be used. He is referring to the fact you cannot use a message property to dynamically control the serial port.

This is how to do it

[{"id":"2f2cbf69a09c4ac4","type":"subflow","name":"Serial port","info":"","category":"","in":[{"x":50,"y":30,"wires":[{"id":"690229bcf4c6ec3a"}]}],"out":[{"x":780,"y":140,"wires":[{"id":"690229bcf4c6ec3a","port":0}]}],"env":[{"name":"port","type":"str","value":""}],"meta":{},"color":"#DDAA99","status":{"x":840,"y":320,"wires":[{"id":"dca0b1adf50129c6","port":0}]}},{"id":"690229bcf4c6ec3a","type":"serial request","z":"2f2cbf69a09c4ac4","name":"","serial":"2d27b1670158b41d","x":430,"y":140,"wires":[[]]},{"id":"dca0b1adf50129c6","type":"status","z":"2f2cbf69a09c4ac4","name":"","scope":null,"x":460,"y":240,"wires":[[]]},{"id":"2d27b1670158b41d","type":"serial-port","z":"2f2cbf69a09c4ac4","serialport":"${port}","serialbaud":"57600","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"\\n","bin":"false","out":"char","addchar":"","responsetimeout":"10000"},{"id":"18799fe40d048acf","type":"subflow:2f2cbf69a09c4ac4","z":"bdd7be38.d3b55","name":"Serial port subflow instance using /dev/ttyUSB0","env":[{"name":"port","value":"/dev/ttyUSB0","type":"str"}],"x":400,"y":2420,"wires":[[]]}]

I have read those documents and I think to have acted accordingly

Ok, now it works.
I was mistakenly defining the env variable value inside the subflow

Thank you so much for your patience and help

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