# Other dynamic parameters in MQTT in

**URL:** <https://discourse.nodered.org/t/other-dynamic-parameters-in-mqtt-in/67329>\
**Category:** General\
**Created:** [4 September 2022 17:39 UTC](https://discourse.nodered.org/t/other-dynamic-parameters-in-mqtt-in/67329 "2022-09-04T17:39:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![greengolfer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greengolfer/32/28276_2.png) [@greengolfer](https://discourse.nodered.org/u/greengolfer)\
**Post date:** [4 September 2022 17:39 UTC](https://discourse.nodered.org/t/other-dynamic-parameters-in-mqtt-in/67329/1 "2022-09-04T17:39:48Z")

</div>

Hello,  
The documentation of the MQTT in node and this post [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) explains how to use the dynamic subscription for:

```auto
broker
For the "connect" action, this property can override any of the individual broker configuration settings, including:
broker
port
url - overrides broker/port to provide a complete connection url
username
password

```

What about the other parameters?

I found that for version 3.1.1 I should use msg.broker.protocolVersion 4

However, how to enable "Use TLS" (tick box), clientID, and configure the TLS part dynamically too?

Is that possible?

Thanks!

---

<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:** [4 September 2022 19:34 UTC](https://discourse.nodered.org/t/other-dynamic-parameters-in-mqtt-in/67329/2 "2022-09-04T19:34:37Z")

</div>

Most properties of the connection can be set dynamically

When `msg.action` == "connect", then `msg.broker` can contain the following....

```auto
{
    url: String,
    broker: String,
    port: Number,
    clientid: String,
    autoConnect: Boolean,
    usetls: Boolean,
    usews: Boolean,
    verifyservercert: Boolean,
    compatmode: Boolean, // true is same as protocolVersion=3 
    protocolVersion: 3|4|5, //v3 | v3.11 (default) | v5
    keepalive: Number,
    cleansession: Boolean,
    sessionExpiry: Number,
    topicAliasMaximum: Number,
    maximumPacketSize: Number,
    receiveMaximum: Number,
    userProperties: String|Object,
    birth: {
        topic: String,
        payload: Any,
        qos: Number,
        retain: Boolean,
        contentType: String,
        userProperties: value,
        responseTopic: String,
        correlationData: String|Buffer,
        messageExpiryInterval: Number,
    },
    close: {
        topic: String,
        payload: Any,
        qos: Number,
        retain: Boolean,
        contentType: String,
        userProperties: value,
        responseTopic: String,
        correlationData: String|Buffer,
        messageExpiryInterval: Number,
    },
    will: {
        topic: String,
        payload: Any,
        qos: Number,
        retain: Boolean,
        contentType: String,
        userProperties: value,
        responseTopic: String,
        correlationData: String|Buffer,
        messageExpiryInterval: Number,
        willDelayInterval: Number, 
    }
}

```

NOTES...

- tls config cannot currently be set dynamically (only turned on/off)
- any setting provided will override existing
  - e.g. you can simply change the `protocolVersion` and all other settings will remain the same.
  - In simple terms, dont include a setting if you dont want to change it.

---

<div class="post-metadata">

**Author:** ![greengolfer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/greengolfer/32/28276_2.png) [@greengolfer](https://discourse.nodered.org/u/greengolfer)\
**Post date:** [4 September 2022 20:10 UTC](https://discourse.nodered.org/t/other-dynamic-parameters-in-mqtt-in/67329/3 "2022-09-04T20:10:44Z")

</div>

Thanks for the quick and comprehensive answer. I may add as usual 🙂

I don't understand what:

- url
- usews  
are.

If the broker String starts with ws or wss it declares it as a websocket broker. So, what is the benefit of using `usews: true`

Another question, do I need `usetls: true` (or box ticked) for the client to use MQTTS or WSS to connect to the broker? If the broker config starts with wss:// is it implicit that it has to use TLS?

Finally, for the tls config, one option could be to declare fix names in the configuration and push the "right" cert, key and ca in another flow...  
I just need to check if usetls is true, I have "fix" files for the ca/cert/key and they are not present if everything works anyhow.

And for url, I can't see that in the config...

---

<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:** [4 September 2022 20:56 UTC](https://discourse.nodered.org/t/other-dynamic-parameters-in-mqtt-in/67329/4 "2022-09-04T20:56:11Z")

</div>

> [@greengolfer](#):
>
> I don't understand what:
> 
> - url

👇

> [@greengolfer](#):
>
> `url - overrides broker/port to provide a complete connection url`

In basic terms...

```auto
msg.broker.broker = 'ip.ip.ip.ip'
msg.broker.port = '1883'

```

is the same as

```auto
msg.broker.url = 'mqtt://ip.ip.ip.ip:1883'

```

  
  

```auto
msg.broker.broker = 'ip.ip.ip.ip'
msg.broker.port = '11883'
msg.broker.usetls = true

```

is the same as

```auto
msg.broker.url = 'mqtts://ip.ip.ip.ip:11883'

```

  
  

As it happens, just been looking at the code. I have just noticed `usews` doesnt actually do anything so to use ws or wss you have to set the `url`

e.g...

```auto
msg.broker.url = 'ws://ip.ip.ip.ip:8883'

```

or

```auto
msg.broker.usetls = true
msg.broker.url = 'wss://ip.ip.ip.ip:18883'

```

---

<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:** [18 September 2022 20:57 UTC](https://discourse.nodered.org/t/other-dynamic-parameters-in-mqtt-in/67329/5 "2022-09-18T20:57:09Z")

</div>

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