# Can I input host,port,user,pass, topic to subscribe in MQTT node?

**URL:** <https://discourse.nodered.org/t/can-i-input-host-port-user-pass-topic-to-subscribe-in-mqtt-node/70876>\
**Category:** General\
**Tags:** function-node, mqtt\
**Created:** [19 November 2022 15:48 UTC](https://discourse.nodered.org/t/can-i-input-host-port-user-pass-topic-to-subscribe-in-mqtt-node/70876 "2022-11-19T15:48:58Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![yingkhun](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yingkhun/32/39651_2.png) [@yingkhun](https://discourse.nodered.org/u/yingkhun)\
**Post date:** [19 November 2022 15:48 UTC](https://discourse.nodered.org/t/can-i-input-host-port-user-pass-topic-to-subscribe-in-mqtt-node/70876/1 "2022-11-19T15:48:58Z")

</div>

can I input host, port, user, pass, topic in MQTT node?

I don't want to add a new MQTT broker because I have a lot of MQTT brokers (one device one broker)

Thank you

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [19 November 2022 16:10 UTC](https://discourse.nodered.org/t/can-i-input-host-port-user-pass-topic-to-subscribe-in-mqtt-node/70876/2 "2022-11-19T16:10:28Z")

</div>

> [@yingkhun](#):
>
> I input host, port, user, pass, topic in MQTT node

Yes, via the broker config screen.

> [@yingkhun](#):
>
> I don't want to add a new MQTT broker because I have a lot of MQTT brokers (one device one broker)

What do you mean by not wanting to add a new broker? When you select that in the MQTT node you are not actually creating a new broker (a broker is software running in a device), you are just configuring access to an existing broker.

When you say you have one broker per device do you mean that you have installed something like mosquitto on each device? There is no need to do that if you don't want to, you can use one cetral broker that all your devices use.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [19 November 2022 16:18 UTC](https://discourse.nodered.org/t/can-i-input-host-port-user-pass-topic-to-subscribe-in-mqtt-node/70876/3 "2022-11-19T16:18:17Z")

</div>

According to [this thread](https://discourse.nodered.org/t/dynamic-mqtt-nodes-actions-connect-guidance-needed/58878), all of the brokers you want to use have to be already set up, but in Dynamic mode you can use msg.action and properties of msg.broker to switch between them.

It does seem a little eccentric to have one mqtt broker per device, akin to having one CNN server per news story.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [19 November 2022 16:35 UTC](https://discourse.nodered.org/t/can-i-input-host-port-user-pass-topic-to-subscribe-in-mqtt-node/70876/4 "2022-11-19T16:35:34Z")

</div>

> [@jbudd](#):
>
> all of the brokers you want to use have to be already set up, but in Dynamic mode you can use msg.action and properties of msg.broker to switch between them.

I don't think that is quite correct, or at least it is not as I understand it. Looking at the example in the post you linked to you can setup what is effectively a dummy broker config and then at run time set it to connect to any broker that you like (via its IP).

---

<div class="post-metadata">

**Author:** ![yingkhun](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yingkhun/32/39651_2.png) [@yingkhun](https://discourse.nodered.org/u/yingkhun)\
**Post date:** [19 November 2022 17:10 UTC](https://discourse.nodered.org/t/can-i-input-host-port-user-pass-topic-to-subscribe-in-mqtt-node/70876/5 "2022-11-19T17:10:01Z")

</div>

Thanks for reply, Sorry for not clear question I have used Thingsboard it create a new broker user for every device I need to control that's why I don't need to add a new MQTT broker

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [19 November 2022 17:13 UTC](https://discourse.nodered.org/t/can-i-input-host-port-user-pass-topic-to-subscribe-in-mqtt-node/70876/6 "2022-11-19T17:13:08Z")

</div>

> [@yingkhun](#):
>
> I have used Thingsboard it create a new broker user

What is a broker user?

> [@yingkhun](#):
>
> that's why I don't need to add a new MQTT broker

Sorry, that still doesn't make any sense to me. Please try and explain, remembering that I know nothing about Thingsboard. I don't know what you mean by adding a new broker.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [19 November 2022 17:23 UTC](https://discourse.nodered.org/t/can-i-input-host-port-user-pass-topic-to-subscribe-in-mqtt-node/70876/7 "2022-11-19T17:23:38Z")

</div>

Thanks Colin, yes it looks like I misunderstood that thread. It has a single "broker" setup with IP 0.0.0.0.

I confess I'm pretty confused about this but I did get it working once [https://discourse.nodered.org/t/mqtt-dynamic-connection-with-changing-ip-adress/69299/3](https://discourse.nodered.org/t/mqtt-dynamic-connection-with-changing-ip-adress/69299/3).  
I can't replicate that now though, nor at the moment can I get @Steve-Mcl's example to work.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [19 November 2022 17:59 UTC](https://discourse.nodered.org/t/can-i-input-host-port-user-pass-topic-to-subscribe-in-mqtt-node/70876/8 "2022-11-19T17:59:48Z")

</div>

> [@jbudd](#):
>
> I confess I'm pretty confused about this

Hey @jbudd what is the confution? I will try to help.

> [@jbudd](#):
>
> I can't replicate that now though, nor at the moment can I get @Steve-Mcl's example to work

Do you mean this \> [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) \< example doesnt work for you?

It still works for me...  
 ![msedge_4OETFHpA9b](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/b/4b89abe7d533772d9b687372113dab6def19f457.gif)

---

<div class="post-metadata">

**Author:** ![yingkhun](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yingkhun/32/39651_2.png) [@yingkhun](https://discourse.nodered.org/u/yingkhun)\
**Post date:** [20 November 2022 01:43 UTC](https://discourse.nodered.org/t/can-i-input-host-port-user-pass-topic-to-subscribe-in-mqtt-node/70876/9 "2022-11-20T01:43:37Z")

</div>

Thingsboard has the same IP broker with a different username (one device one username) and a different username can't see another username topic it's completely separate not like normal MQTT that's why I don't need to add a new MQTT broker because in longterm its will have a lot of MQTT broker

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [20 November 2022 10:02 UTC](https://discourse.nodered.org/t/can-i-input-host-port-user-pass-topic-to-subscribe-in-mqtt-node/70876/10 "2022-11-20T10:02:20Z")

</div>

The help page for the MQTT In node tells you how to dynamically set the username and password. Did you look at the link that @Steve-Mcl posted that explains how to do it?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [20 November 2022 14:40 UTC](https://discourse.nodered.org/t/can-i-input-host-port-user-pass-topic-to-subscribe-in-mqtt-node/70876/11 "2022-11-20T14:40:42Z")

</div>

> [@Steve-Mcl](#):
>
> what is the confusion? I will try to help.

Thanks Steve,  
Yes your example does work on my test Pi now.  
I just had to update a bunch of stuff: RPiOS, Node-red and Mosquitto.

---

<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:** [19 January 2023 14:40 UTC](https://discourse.nodered.org/t/can-i-input-host-port-user-pass-topic-to-subscribe-in-mqtt-node/70876/12 "2023-01-19T14:40:44Z")

</div>

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