Other dynamic parameters in MQTT in

Hello,
The documentation of the MQTT in node and this post Dynamic MQTT node's "actions->connect" guidance needed - #2 by Steve-Mcl explains how to use the dynamic subscription for:

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!

Most properties of the connection can be set dynamically

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

{
    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.
1 Like

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

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...

:point_down:

In basic terms...

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

is the same as

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


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

is the same as

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...

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

or

msg.broker.usetls = true
msg.broker.url = 'wss://ip.ip.ip.ip:18883'
1 Like

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