Skip to main content
Version: 2.6

MQTT Control Driver Configuration

Plugin Configuration

The plugin configuration file is named settings.json located in $(install directory)\Config\HumanOS.UHAL.MqttControl\. It contains all global settings of the plugin.

See Generic Plugin Configuration for more details.

Device Information File

The device information file is used to configure the access to the MQTT devices. It contains:

  • Id: unique device id (GUID), which MUST match the device license id.
  • DriverId: 11034AA5-13C7-4D05-83E0-361BC816E779
  • Address: Connection address
  • Data Access

See Device Information Model for more details.

Connection Address

The connections are established on TCP Port defined by the device address setting, so make sure it is open. The Address for MQTT Control must be provided like following:

NameDescriptionExample
AddressIP address and Portaddress=10.256.35.32;port=1883

This information is contained by the device configuration.

Additional Device and Connection Properties

The following connection options can be set via the device properties.

NameDescriptionDataType
MqttProtocolThe protocol version of MQTT, possible values are
  • v310
  • v311
  • v500
System.String
ReconnectIntervalWhen the connection to broker cannot established, the task processor tries to reconnect with this interval to the broker. Time unit in millisecondsSystem.Int32
KeepAliveIntervalMQTT can be configured by design with a keep alive interval. This property specifies the KeepAlive interval. Time unit in millisecondsSystem.Int32
ConnectionTimeoutWhen the MQTT plugin is connected to the broker, this timeout specifies how long to wait for an answer from the broker until the connection will be aborted. Time unit in millisecondsSystem.Int32
UsernameMQTT connections can be protected by a username and a password. This property specifies the usernameSystem.String
PasswordThis property specifies the passwordSystem.String
ClientIdEach MQTT client should have an unique id. This property specifies the MQTT client id. Default is the device IdSystem.String
CleanSessionWith this property, the MQTT client can tell the broker not to store session information or the client does not need to get messages that it misses offlineSystem.Boolean
QualityOfServiceThe quality of the messages. Following values are possible:
  • 0: At most once
  • 1: At least once
  • 2: Exactly once
System.Int32
RetainMessagesWith this property enabled, the Plugin will send all Data as retain messagesSystem.Boolean
SslProtocolFor secure connections, the SSL-Protocol can be specified. Possible values are:
  • None
  • SSLv3
  • TLSv1.0
  • TLSv1.1
  • TLSv1.2
  • TLSv1.3
System.String

Device Example

{
"Name": "MQTT Control 1",
"Id": "50EFD36B-95D4-450F-A1FB-16969CE70DB9",
"DriverId": "E78FB177-AEDC-4A3A-A237-B9835738FD68",
"Address": "http://localhost:1883",
"Properties": [
{
"Name": "ClientId",
"Value": "bb6ffeb6"
},
{
"Name": "Username",
"Value": "user"
},
{
"Name": "Password",
"Value": "password"
},
{
"Name": "CleanSession",
"Value": true
},
{
"Name": "KeepAliveInterval",
"Value": 30000
},
{
"Name": "ReconnectInterval",
"Value": 10000
},
{
"Name": "ConnectionTimeout",
"Value": 10000
}
]
}

Custom Task Processor

With the custom task processor, some device specific code can be implemented. To work with custom task processors, the task processor(s) in the device file must be configured.

Following example shows the additional task processor

{
// Task processor to do custom connection details
"TaskProcessors": [
{
"Id": "E63EA07D-1938-47BD-9C23-3D4AED34A97C",
"Name": "CustomTaskProcessor",
"ScriptFile": "TaskProcessors\\TCustomProcessor.cs"
}
]
}

The main class of the task processor script must be derived from TAbstractMqttProcessingScriptObject. The method doProcess() is called every time the task processor is executed and the device is connected.
onConnectedToDevice() is called every time the UHAL Plugin is connected to the broker.
onDisconnectFromDevice() is called every time the UHAL Plugin is disconnected from the broker.

Following example shows the script

using CyberTech.Diagnostics;
using HumanOS.Kernel;
using HumanOS.Kernel.Processing;
using HumanOS.Kernel.UHAL.InfoModel;
using HumanOS.UHAL.MqttControl.Script;
using MQTTnet.Client;

namespace HumanOS.IoT.Designer.Library.Scripts
{
/// <summary>
/// Example for MQTT processing
/// </summary>
public class Blank_UHALMqttProcessingScriptObject : TAbstractMqttProcessingScriptObject
{
///<see cref="TAbstractMqttProcessingScriptObject"/>
public override void doProcess(IKernelAccess Kernel, TDeviceSchemaInfo DeviceInfo, ILogger Logger, IMqttClient nClient)
{
}

///<see cref="TAbstractMqttProcessingScriptObject"/>
public override EProcessingState onConnectedToDevice(IKernelAccess Kernel, TDeviceSchemaInfo DeviceInfo, ILogger Logger, IMqttClient nClient)
{
return base.onConnectedToDevice(Kernel, DeviceInfo, Logger, nClient);
}

///<see cref="TAbstractMqttProcessingScriptObject"/>
public override void onDisconnectFromDevice(IKernelAccess Kernel, TDeviceSchemaInfo DeviceInfo, ILogger Logger, IMqttClient nClient)
{
base.onDisconnectFromDevice(Kernel, DeviceInfo, Logger, nClient);
}
}
}