[mqtt] Add missing broker connection configuration parameters (#13303)

Allows to configure the following broker connection configuration parameters:

* Protocol: TCP (default), WEBSOCKETS
* MQTT Version: V3 (default), V5
* Hostname Validation: true (default), false

The defaults are chosen to remain backwards compatible.

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born 2022-08-26 08:53:00 +02:00 committed by GitHub
parent c21d3061ec
commit cfa20db227
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 2 deletions

View File

@ -28,6 +28,9 @@ Required configuration parameters are:
Additionally the following parameters can be set: Additionally the following parameters can be set:
* __hostnameValidated__: Validate hostname from certificate against server hostname for secure connection. Defaults to true.
* __protocol__: The protocol used for communicating with the broker (TCP, WEBSOCKETS). Defaults to TCP.
* __mqttVersion__: The MQTT version used for communicating with the broker (V3, V5). Defaults to V3.
* __qos__: Quality of Service. Can be 0, 1 or 2. Please read the MQTT specification for details. Defaults to 0. * __qos__: Quality of Service. Can be 0, 1 or 2. Please read the MQTT specification for details. Defaults to 0.
* __clientID__: Use a fixed client ID. Defaults to empty which means a user ID is generated for this connection. * __clientID__: Use a fixed client ID. Defaults to empty which means a user ID is generated for this connection.

View File

@ -200,8 +200,8 @@ public class BrokerHandler extends AbstractBrokerHandler implements PinnedCallba
throw new IllegalArgumentException("Host is empty!"); throw new IllegalArgumentException("Host is empty!");
} }
final MqttBrokerConnection connection = new MqttBrokerConnection(host, config.port, config.secure, final MqttBrokerConnection connection = new MqttBrokerConnection(config.protocol, config.mqttVersion, host,
config.clientID); config.port, config.secure, config.hostnameValidated, config.clientID);
final String username = config.username; final String username = config.username;
final String password = config.password; final String password = config.password;

View File

@ -26,6 +26,8 @@ thing-type.config.mqtt.broker.enableDiscovery.label = Enable Discovery
thing-type.config.mqtt.broker.enableDiscovery.description = If set to true enables this broker for all discovery services. thing-type.config.mqtt.broker.enableDiscovery.description = If set to true enables this broker for all discovery services.
thing-type.config.mqtt.broker.host.label = Broker Hostname/IP thing-type.config.mqtt.broker.host.label = Broker Hostname/IP
thing-type.config.mqtt.broker.host.description = The IP/Hostname of the MQTT broker thing-type.config.mqtt.broker.host.description = The IP/Hostname of the MQTT broker
thing-type.config.mqtt.broker.hostnameValidated.label = Hostname Validated
thing-type.config.mqtt.broker.hostnameValidated.description = Validate hostname from certificate against server hostname for secure connection.
thing-type.config.mqtt.broker.keepAlive.label = Heartbeat thing-type.config.mqtt.broker.keepAlive.label = Heartbeat
thing-type.config.mqtt.broker.keepAlive.description = Keep alive / heartbeat timer in s. It can take up to this time to determine if a server connection is lost. A lower value may keep the broker unnecessarily busy for no or little additional value. thing-type.config.mqtt.broker.keepAlive.description = Keep alive / heartbeat timer in s. It can take up to this time to determine if a server connection is lost. A lower value may keep the broker unnecessarily busy for no or little additional value.
thing-type.config.mqtt.broker.lwtMessage.label = Last Will Message thing-type.config.mqtt.broker.lwtMessage.label = Last Will Message
@ -39,10 +41,18 @@ thing-type.config.mqtt.broker.lwtRetain.label = Last Will Retain
thing-type.config.mqtt.broker.lwtRetain.description = True if last Will should be retained (defaults to false) thing-type.config.mqtt.broker.lwtRetain.description = True if last Will should be retained (defaults to false)
thing-type.config.mqtt.broker.lwtTopic.label = Last Will Topic thing-type.config.mqtt.broker.lwtTopic.label = Last Will Topic
thing-type.config.mqtt.broker.lwtTopic.description = Defaults to empty and therefore disables the last will. thing-type.config.mqtt.broker.lwtTopic.description = Defaults to empty and therefore disables the last will.
thing-type.config.mqtt.broker.mqttVersion.label = MQTT Version
thing-type.config.mqtt.broker.mqttVersion.description = The MQTT version used for communicating with the broker.
thing-type.config.mqtt.broker.mqttVersion.option.V3 = Version 3
thing-type.config.mqtt.broker.mqttVersion.option.V5 = Version 5
thing-type.config.mqtt.broker.password.label = Password thing-type.config.mqtt.broker.password.label = Password
thing-type.config.mqtt.broker.password.description = The MQTT password thing-type.config.mqtt.broker.password.description = The MQTT password
thing-type.config.mqtt.broker.port.label = Broker Port thing-type.config.mqtt.broker.port.label = Broker Port
thing-type.config.mqtt.broker.port.description = The port is optional, if none is provided, the typical ports 1883 and 8883 (SSL) are used. thing-type.config.mqtt.broker.port.description = The port is optional, if none is provided, the typical ports 1883 and 8883 (SSL) are used.
thing-type.config.mqtt.broker.protocol.label = Protocol
thing-type.config.mqtt.broker.protocol.description = The protocol used for communicating with the broker.
thing-type.config.mqtt.broker.protocol.option.TCP = TCP
thing-type.config.mqtt.broker.protocol.option.WEBSOCKETS = WebSockets
thing-type.config.mqtt.broker.publickey.label = Public Key Hash thing-type.config.mqtt.broker.publickey.label = Public Key Hash
thing-type.config.mqtt.broker.publickey.description = If **publickeypin** is set this hash is used to verify the connection. Clear to allow a new public key pinning on the next connection attempt. If empty will be filled automatically by the next successful connection. An example input would be `SHA-256:83F9171E06A313118889F7D79302BD1B7A2042EE0CFD029ABF8DD06FFA6CD9D3` thing-type.config.mqtt.broker.publickey.description = If **publickeypin** is set this hash is used to verify the connection. Clear to allow a new public key pinning on the next connection attempt. If empty will be filled automatically by the next successful connection. An example input would be `SHA-256:83F9171E06A313118889F7D79302BD1B7A2042EE0CFD029ABF8DD06FFA6CD9D3`
thing-type.config.mqtt.broker.publickeypin.label = Public Key Pinning thing-type.config.mqtt.broker.publickeypin.label = Public Key Pinning

View File

@ -29,6 +29,35 @@
<default>false</default> <default>false</default>
</parameter> </parameter>
<parameter name="hostnameValidated" type="boolean">
<label>Hostname Validated</label>
<description>Validate hostname from certificate against server hostname for secure connection.</description>
<default>true</default>
<advanced>true</advanced>
</parameter>
<parameter name="protocol" type="text">
<label>Protocol</label>
<description>The protocol used for communicating with the broker.</description>
<options>
<option value="TCP">TCP</option>
<option value="WEBSOCKETS">WebSockets</option>
</options>
<default>TCP</default>
<advanced>true</advanced>
</parameter>
<parameter name="mqttVersion" type="text">
<label>MQTT Version</label>
<description>The MQTT version used for communicating with the broker.</description>
<options>
<option value="V3">Version 3</option>
<option value="V5">Version 5</option>
</options>
<default>V3</default>
<advanced>true</advanced>
</parameter>
<parameter name="qos" type="integer"> <parameter name="qos" type="integer">
<label>Quality of Service</label> <label>Quality of Service</label>
<options> <options>