]> git.basschouten.com Git - openhab-addons.git/commitdiff
[mqtt] Add missing broker connection configuration parameters (#13303)
authorWouter Born <github@maindrain.net>
Fri, 26 Aug 2022 06:53:00 +0000 (08:53 +0200)
committerGitHub <noreply@github.com>
Fri, 26 Aug 2022 06:53:00 +0000 (08:53 +0200)
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>
bundles/org.openhab.binding.mqtt/README.md
bundles/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/handler/BrokerHandler.java
bundles/org.openhab.binding.mqtt/src/main/resources/OH-INF/i18n/mqtt.properties
bundles/org.openhab.binding.mqtt/src/main/resources/OH-INF/thing/thing-types.xml

index b41323a04c9ea9c6e27be82803c11c99aa1183c3..02fe391284e19ec681a16eb33cbbc348c6c14545 100644 (file)
@@ -28,6 +28,9 @@ Required configuration parameters are:
 
 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.
 * __clientID__: Use a fixed client ID. Defaults to empty which means a user ID is generated for this connection.
 
index 617050e6f8e21ba9616d4d3da1fbd749bb4d7ecd..187231220de9c5989514f69c80c2649e708ebbd4 100644 (file)
@@ -200,8 +200,8 @@ public class BrokerHandler extends AbstractBrokerHandler implements PinnedCallba
             throw new IllegalArgumentException("Host is empty!");
         }
 
-        final MqttBrokerConnection connection = new MqttBrokerConnection(host, config.port, config.secure,
-                config.clientID);
+        final MqttBrokerConnection connection = new MqttBrokerConnection(config.protocol, config.mqttVersion, host,
+                config.port, config.secure, config.hostnameValidated, config.clientID);
 
         final String username = config.username;
         final String password = config.password;
index 029ae60fa8f313d441afbe13a809372bf96302bb..dcb27b71aed4e1daf9c378682d6d92e5a03f504a 100644 (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.host.label = Broker Hostname/IP
 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.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
@@ -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.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.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.description = The MQTT password
 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.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.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
index 0f9f5a68aa53c726edf55c227cc7d493cba34b12..d818ac8b8891674493ac7a460e62599a012fb12c 100644 (file)
                                <default>false</default>
                        </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">
                                <label>Quality of Service</label>
                                <options>