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

**URL:** <https://discourse.nodered.org/t/how-to-set-the-default-values-of-mqtt-in-and-out-nodes-to-known-broker-addresses-and-ports-on-node-red-start-up/61598>\
**Category:** General\
**Tags:** mqtt\
**Created:** [21 April 2022 13:27 UTC](https://discourse.nodered.org/t/how-to-set-the-default-values-of-mqtt-in-and-out-nodes-to-known-broker-addresses-and-ports-on-node-red-start-up/61598 "2022-04-21T13:27:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shan](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@Shan](https://discourse.nodered.org/u/Shan)\
**Post date:** [21 April 2022 13:27 UTC](https://discourse.nodered.org/t/how-to-set-the-default-values-of-mqtt-in-and-out-nodes-to-known-broker-addresses-and-ports-on-node-red-start-up/61598/1 "2022-04-21T13:27:21Z")

</div>

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](https://nodered.org/docs/creating-nodes/config-nodes)

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

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [21 April 2022 20:31 UTC](https://discourse.nodered.org/t/how-to-set-the-default-values-of-mqtt-in-and-out-nodes-to-known-broker-addresses-and-ports-on-node-red-start-up/61598/2 "2022-04-21T20:31:45Z")

</div>

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

 ![Screenshot 2022-04-21 at 22.16.55](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/d/6dc4eb71b99f815566c48e9bb84e053dbf83e187.jpeg)

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

```auto
msg = {
    action: "connect",
    broker:"my broker",
    port: "1883",
    url: "mqtt://ipaddress",
    username:"",
    password:"",
}

return msg;

```

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

 ![Screenshot 2022-04-21 at 22.30.16](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/e/cef0d2907bbdfee3950e953032d7fdcaff3a5119.jpeg)

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.

---

<div class="post-metadata">

**Author:** ![Shan](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@Shan](https://discourse.nodered.org/u/Shan)\
**Post date:** [21 April 2022 20:48 UTC](https://discourse.nodered.org/t/how-to-set-the-default-values-of-mqtt-in-and-out-nodes-to-known-broker-addresses-and-ports-on-node-red-start-up/61598/3 "2022-04-21T20:48:38Z")

</div>

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](https://discourse.nodered.org/t/dynamic-mqtt-nodes-actions-connect-guidance-needed/58878/2)

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?

## Edit

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [5 May 2022 20:48 UTC](https://discourse.nodered.org/t/how-to-set-the-default-values-of-mqtt-in-and-out-nodes-to-known-broker-addresses-and-ports-on-node-red-start-up/61598/4 "2022-05-05T20:48:44Z")

</div>

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