# Dynamic MQTT broker via url not working for me

**URL:** <https://discourse.nodered.org/t/dynamic-mqtt-broker-via-url-not-working-for-me/67555>\
**Category:** General\
**Created:** [10 September 2022 15:43 UTC](https://discourse.nodered.org/t/dynamic-mqtt-broker-via-url-not-working-for-me/67555 "2022-09-10T15:43:27Z")\
**Posts on this page:** 4\
**Page:** 1

<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:** [10 September 2022 15:43 UTC](https://discourse.nodered.org/t/dynamic-mqtt-broker-via-url-not-working-for-me/67555/1 "2022-09-10T15:43:27Z")

</div>

I am experimenting with Dynamic MQTT configuration, and have a couple of problems. I will ask about them separately to avoid confusing threads.

I can't get it to work using `msg.broker.url` to specify the broker. if I setup `msg.broker` to contain `broker` and `port` separately then it works. I assume that the url should be of the form "localhost:1883". This flow demonstrates the problem. I am using node-red 3.0.2 with nodejs 16.

```auto
[{"id":"518225cfb1b5fb8c","type":"inject","z":"bdd7be38.d3b55","name":"Disconnect","props":[{"p":"action","v":"disconnect","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":140,"y":3120,"wires":[["02a1909dcc82a87e"]]},{"id":"59aa2f05e0a8c24c","type":"inject","z":"bdd7be38.d3b55","name":"Connect via broker, port","props":[{"p":"action","v":"connect","vt":"str"},{"p":"broker","v":"{\"broker\":\"localhost\",\"port\":\"1883\"}","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":180,"y":3200,"wires":[["02a1909dcc82a87e"]]},{"id":"02a1909dcc82a87e","type":"mqtt in","z":"bdd7be38.d3b55","name":"","topic":"","qos":"0","datatype":"auto-detect","broker":"f009e0d5c98277d8","nl":false,"rap":true,"rh":0,"inputs":1,"x":350,"y":3140,"wires":[[]]},{"id":"0be15fef04b453e2","type":"inject","z":"bdd7be38.d3b55","name":"Connect via url","props":[{"p":"action","v":"connect","vt":"str"},{"p":"broker","v":"{\"url\": \"localhost:1883\"}","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":160,"y":3160,"wires":[["02a1909dcc82a87e"]]},{"id":"f009e0d5c98277d8","type":"mqtt-broker","name":"Dynamic","broker":"0.0.0.0","port":"0","clientid":"","autoConnect":false,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]

```

---

<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:** [10 September 2022 15:57 UTC](https://discourse.nodered.org/t/dynamic-mqtt-broker-via-url-not-working-for-me/67555/2 "2022-09-10T15:57:40Z")

</div>

> [@Colin](#):
>
> I assume that the url should be of the form "localhost:1883"

It should be...

Protocol://hostname:port

e.g...

- `mqtt://localhost:1883`
- `mqtts://localhost:8883`
- `ws://localhost:1884`
- `wss://localhost:8884`

---

<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:** [10 September 2022 19:58 UTC](https://discourse.nodered.org/t/dynamic-mqtt-broker-via-url-not-working-for-me/67555/3 "2022-09-10T19:58:21Z")

</div>

Oh Yes, thanks. All working now.

---

<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:** [24 September 2022 19:58 UTC](https://discourse.nodered.org/t/dynamic-mqtt-broker-via-url-not-working-for-me/67555/4 "2022-09-24T19:58:37Z")

</div>

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