Use config property of subflow in mqtt-nodes

Hello,

I have to connect my software to four (or more - in the future) MQTT-Servers a once. All MQTT-Servers are of the same kind. My idea is to create a subflow which contains the [mqtt-in]- and [mqtt-out]-nodes. The subflow has a "serverNr" property. At the subflow input only messagens with correct serverNr are forwarded to the [mqtt-out]-node. At the subflow output all messages from the [mqtt-in]-node are marked with the serverNr.
My Question is: How do I set different MQTT-configuration nodes for instances of the subflow? I figured out, that it is possible to set a configuration node as subflow-property but I don't unterstand how to use this property in the server property of the [mqtt-in]- and [mqtt-out]-nodes.

Thanks a lot for every useful hint.
LaLe

Can you explain what you mean by MQTT-Servers, and why four of them?
MQTT has a broker rather than a server, and it would be an unusual situation where you need to publish or subscribe to topics on more than one broker.

The mqtt nodes allow dynamic connect/disconnect, so the subflow can connect to the relevant broker based on your "serverNR" property (do you mean msg.serverNR? )

You can also change the broker config to be owned by the subflow - that way each instance gets their own broker


After you add the config env var in the subflow template, when you edit an MQTT in/out inside the subflow template, the dropdown will have an [env] xxxx entry.

when you create an instance of the subflow, you can select which broker config to use


Personally, i just avoid this whole pattern and generate the required brokers so I can drop MQTT nodes wherever I please on the flows without the worry of instantiating multiples or feeding every message to a subflow instance (it just gets too messy for my liking)

I think this does what you want

[{"id":"eb57e20faeb27863","type":"subflow","name":"MQTT subflow","info":"","category":"","in":[],"out":[],"env":[{"name":"Broker","type":"mqtt-broker","value":"","ui":{"type":"conf-types"}}],"meta":{},"color":"#DDAA99"},{"id":"4d13d7b6754afeee","type":"mqtt in","z":"eb57e20faeb27863","name":"","topic":"test/topic","qos":"2","datatype":"auto-detect","broker":"${Broker}","nl":false,"rap":true,"rh":0,"inputs":0,"x":190,"y":80,"wires":[[]]},{"id":"45545b463a4e5330","type":"subflow:eb57e20faeb27863","z":"997da33a0beedade","name":"","env":[{"name":"Broker","value":"05a2c22533d7eb1b","type":"conf-type"},{"name":"MQTTBroker","value":"localhost","type":"env"}],"x":420,"y":2480,"wires":[]}]

Hello jbudd,
I far as I understand the regular term is "MQTT broker", NodeRED uses Server instead. This is a NodeRED Forum, so I used the NodeRED convention.
I want to connect to four of them because I used four propertarian systems, each of them is equipped with an own MQTT Server. I want to build a central status display. I think there is no was to persuade the manufactor to publish on an MQTT server of my choice.

Unfortunately the MQTT node's broker selection field is named Server. I suppose you could say it is the IP/hostname of the server running the broker.

"Broker" is the more functional description of an "MQTT Server", while "Server" is the more technical wording for a system wainting clients to connect to a provided service - here "MQTT Brokerage". Some sort of "Matter of Taste".

Hello Steve-Mcl,

thank you very much. I think your pictures will show me the way. I will try it tomorrow and give feedback / mark it as solution.

Yes it is labelled Server and if you click the Add or Edit buttons it takes you to
image
or
image

Unfortunately Node-red is rife with has several such inconsistencies :neutral_face: