How to set the default values of MQTT In and Out Nodes to known broker addresses and ports on node-red start up?

I am using node-red with v2.2.2 via docker compose environment where I already have two MQTT brokers configured. Since the node-red container and the two eclipse-mosquitto brokers are in the same docker network I wish to configure the MQTT In and MQTT Out nodes already pre-configured to show the two broker names upon double-clicking on them, namely

internal-mqtt-broker has broker address set to internal-mqtt (container-name) with port 1886
external-mqtt-broker has broker address set to external-mqtt (container-name) with port 1883

I am going through the Documentation for Custom Config Nodes Configuration nodes : Node-RED

But since I do not wish to create a new node itself, how can I override the default value for the MQTT In and MQTT Out node with the above mentioned values?

I wish to avoid developing a custom node-red container here and want to use it out of the container?

I would like the user to be presented with the available broker already, once they drag the nodes in the editor

The mqtt-in node can be configured to accept dynamic connections:

Then you can attach a function node with your mqtt broker connection details

msg = {
    action: "connect",
    broker:"my broker",
    port: "1883",
    url: "mqtt://ipaddress",

return msg;

Once injected, you can subscribe to topics by using another inject/function node that sends the subscribe action:

All actions for connecting/disconnecting/subscribing/unscribing are documented in the node (ie. select the mqtt-in node and select the documentation tab on the right side of the node-red ui).

This you could wrap inside a subflow which appears in the node palette.

Thanks for this. I will try this and report back to this thread. I am aware of Dynamic Connections in MQTT based on Dynamic MQTT node's "actions->connect" guidance needed - #2 by Steve-Mcl

So based on your suggestion, and if I understand it correctly, if I pack the function (or even a change node as mentioned in the thread above) with a dynamic subscription MQTT in a subflow, it can then be made available as _node_itself for the end user?


as mentioned by @bakman2 I created a pair of subflows for each mqtt broker (4 in total)

  • internal mqtt broker in node
  • internal mqtt broker out node
  • external mqtt broker in node
  • external mqtt broker out node

This make it easier for me to drag-and-drop specific mqtt brokers into the flow

1 Like

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