Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info
iconfalse

Quick video tutorial: MQTT Broker Without Sparkplug TMQTT Broker And SparkplugMQTT With Mosquitto Broker (no audio)

Introduction

Inside the product installation folder, you will find an executable file called TMQTTBroker.exe. To run it, double click on the file. Once the file is running, a blue icon will appear in the Windows System Tray. The MQTT Broker will run by following the specifications configured in the TMQTTBroker.exe.config file. You can find more information regarding this in the next section. 

The Broker can run as a Windows service by running the file InstallTMQTTBrokerAsService.exe, which is also found in the product installation folder. The MQTT Broker accepts connections with MQTT clients by following the SparkplugB specification. Also, it accepts connections with pure MQTT clients, who do not use SparkplugB, as Mosquitto clients.

The TMQTTBroker can be connected to a runtime project, and it will make all of the project's namespaces and properties available. When connected like this, the project information will be available following the SparkplugB specification. 

TMQQTBroker.exe.config

Before running TMQTTBroker.exe, the file TMQTTBroker.exe.config must be configured with the desired configuration. TMQTTBroker.exe.config is in the product installation folder, and you can open it in any text editor. It is very important that the file name and extension (.exe.config) remain the same.

When you open the TMQTTBroker.exe.config file, you will find all of the possible configured parameters. The parameters will be comments surrounded by (<!−−   −−>). To set a specific parameter, you need to move the whole line of the parameter outside the comments (<!−−    −−>) but keep it in the section <configuration> <appSettings>.

Example of the whole line you need to move:

Code Block
<add key="ListeningPort" value="1883"/>

When you run the MQTT Broker with the default configuration (without changing the .config file), it will assume the parameters below:

  • Listening port: 1883
  • UserNameAndPassword1: none
  • CertificateFile: none   
  • CertificatePassword: none

Below is the complete list of parameters found in the .config file and their respective description.

MQTT

As defined in http://mqtt.org/:

”MQTT is a machine-to-machine (M2M)/”Internet of Things” connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport. It is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium. For example, it has been used in sensors communicating to a broker via satellite link, over occasional dial-up connections with healthcare providers, and in a range of home automation and small device scenarios. It is also ideal for mobile applications because of its small size, low power usage, minimized data packets, and efficient distribution of information to one or many receivers (more...)”.

Sparkplug B

As defined in https://www.bevywise.com/blog/sparkplug-b-mqtt-simulation/.

Sparkplug provides an open and freely available specification for how Edge of Network (EoN) gateways or native MQTT enabled end devices and MQTT Applications communicate bi-directionally within an MQTT Infrastructure. One of the unique aspects of MQTT is that it was originally designed for real time SCADA systems to help reduce data latency over bandwidth limited and often unreliable network infrastructure. Similarly the intent of the Sparkplug specification is to take full advantage of MQTT’s native Continuous Session Awareness capability as it applies to real time SCADA/IIoT solutions.

Inside the product installation folder, you will find an executable file called TMQTTBroker.exe. To run it, double click on the file. Once the file is running, a blue icon will appear in the Windows System Tray. The MQTT Broker will run by following the specifications configured in the TMQTTBroker.exe.config file. You can find more information regarding this in the next section. 

The Broker can run as a Windows service by running the file InstallTMQTTBrokerAsService.exe, which is also found in the product installation folder. The MQTT Broker accepts connections with MQTT clients by following the SparkplugB specification. Also, it accepts connections with pure MQTT clients, who do not use SparkplugB, as Mosquitto clients.

The TMQTTBroker can be connected to a runtime project, and it will make all of the project's namespaces and properties available. When connected like this, the project information will be available following the SparkplugB specification. 


...

TMQTTBroker.exe.config

Before running TMQTTBroker.exe, the file TMQTTBroker.exe.config must be configured with the desired configuration. TMQTTBroker.exe.config is in the product installation folder, and you can open it in any text editor. It is very important that the file name and extension (.exe.config) remain the same.

When you open the TMQTTBroker.exe.config file, you will find all of the possible configured parameters. The parameters will be comments surrounded by (<!−−   −−>). To set a specific parameter, you need to move the whole line of the parameter outside the comments (<!−−    −−>) but keep it in the section <configuration> <appSettings>.

Example of the whole line you need to move:

Code Block
<add key="ListeningPort" value="1883"/>


When you run the MQTT Broker with the default configuration (without changing the .config file), it will assume the parameters below:

  • Listening port: 1883
  • UserNameAndPassword1: none
  • CertificateFile: none   
  • CertificatePassword: none


Below is the complete list of parameters found in the .config file and their respective description.

Code Block
<appSettings>
<add key="ListeningPort" value="1883
Code Block
<appSettings>
<add key="ListeningPort" value="1883"/>
<add key="Backlog" value="100"/>
<add key="GroupId" value="TServer"/>
<add key="TimeUpdateTServers" value="500"/>
<add key="DisableRetainedFile" value="false"/>
<add key="CertificateFile" value=""/>
<add key="CertificatePasswordBacklog" value="100"/>
<add key="SslProtocolsGroupId" value="Tls12TServer"/>
<add key="UserNameAndPassword1TimeUpdateTServers" value="Test;#3B43F58BFF9AFF8CFF8BFFCDFF500"/>
<add  key="ClientID1DisableRetainedFile"  value="ClientID01;Topic1=*,Subscribe1=True,Publish1=Truefalse"/>
<add key="CertificateFile" value=""/>
<add  key="ClientID2CertificatePassword"  value="ClientID02;Topic1=*,Subscribe1=True,Publish1=True"/>
<add key="TServer1SslProtocols" value="<ProjectName>;localhost:3101Tls12"/>
<add  key="TagPropertiesUserNameAndPassword1"  value="MinTest;Max#3B43F58BFF9AFF8CFF8BFFCDFF"/>
</appSettings>
  • ListeningPort: Server listening port. The default is 1883 if it is not configured 
  • CertificateFile: Certificate file to use in the SSL
  • CertificatePassword: Certificate password to use in the SSL
  • SslProtocols: SSL protocol
  • UserNameAndPassword1: UserName and password required to access the Broker, using the syntax UserName;Password.
<add  key="ClientID1"  value="ClientID01;Topic1=*,Subscribe1=True,Publish1=True"/>
<add  key="ClientID2"  value="ClientID02;Topic1=*,Subscribe1=True,Publish1=True"/>
<add key="TServer1" value="<ProjectName>;localhost:3101"/>
<add  key="TagProperties"  value="Min;Max"/>
</appSettings>


  • ListeningPort: Server listening port. The default is 1883 if it is not configured 
  • CertificateFile: Certificate file to use in the SSL
  • CertificatePassword: Certificate password to use in the SSL
  • SslProtocols: SSL protocol
  • UserNameAndPassword1: UserName and password required to access the Broker, using the syntax UserName;Password.


The password The password can be a string with no encryption or an encrypted password. To encrypt a password you can use in any coder (ex. Visual Studio), use the following code:

...

  • Backlog: Sets the number of connections to keep a backlog. The default is 100. 
  • DisableRetainedFile: The broker stores the last retained message and the corresponding QoS for that topic. The valid value is true or false. The default is false.

  • ClientID: This parameter enables limitations for specific MQTT clients. To configure more than one MQTT client, you need to create a whole new line and change the last number of the ClientID to the next sequence sequential number.


    Code Block
    add key="ClientID1" value="<MQTTClientID>; Topic1=<Topic>, Subscribe1=<True or False>, Publish1=<True or False>" />


    There are 4 internal parameters:

  • value: Sets the MQTT Client ID
  • Topic: Specific topic that will set the limitation
  • Subscribe: Flag (true or false) that allows the client to subscribe to a topic (can receive messages)
  • Publish: Flag (true or false) that allows the client to publish a topic (can write messages) 

    Code Block
    <add  key="ClientID1"  value="MQTTClientTest;Topic1=*,Subscribe1=True,  Publish1=True"/>
    
    <add  key="ClientID2"  value="32443fsa6546fa;Topic1=*,Subscribe1=True,  Publish1=False"/>
    
    <add  key="ClientID3"  value="7323rt304343r4;Topic1=*,Subscribe1=False,Publish1=True"/>


...

  • Group Id: is the name that is configured in the .config
  • Message Type: The following Message Type elements are defined for the Sparkplug specification. For most clients that support SparkplugB, the message type will automatically be set. 
  • NBIRTH – Birth certificate for MQTT EoN
  • NDEATH – Death certificate for MQTT EoN
  • DBIRTH – Birth certificate for devices
  • DDEATH – Death certificate for devices
  • NDATA – Node data
  • DDATA – Device data
  • NCMD – Node command
  • DCMD – Device command
  • STATE – Critical application state
  • Project Name: is the same name configured in the .config
  • MQTT Device Name: it can be a namespace or an object from the runtime project. Individual However, individual objects should be avoided and uses the namespaces for . Use a namespace for better performance


Examples of namespaces: Tag, Script, Device, Info, Script, Server, Security, Alarm, Historian DataSets, TemplatesName and MainTag for arrays.

...

In this scenario, the TMQTTBroker works as if you combined the last two scenarios are combined together. As This means a simple gateway exchange any exchanges data between the MQTT Clients and publishing publishes project data projects to the topics that match the project configuration in the TMQTTBroker.exe.config.

...

MQTT driver (without SparkPugB)

The first step in setting to set up communication between the TMQTTBroker and the MQTTdriver is to create a Channel using the protocol shown in the image below.

...

MQTTSpB driver (SparkPlugB)

The first step in setting to set up communication between MQTT + SparkPlug Driver and the TMQTT Broker is to create a Channel using this the protocol shown in the image below. 


In the Engineering environment, go to Edit>Devices>Channels and find the desired protocol inside the list.

...

You can set up communication between the TMQTT Broker with and third party MQTT Clients. In this example, we use MQTT.fx.

To configure this clientMQTT.fx, the following steps are required:

...

Note

It is worth mentioning that its not required to point to each element individually for an array tag. The broker is smart enough to fetch all data by just receiving the main tag element. The same happens for tags with template datatypes.



There is more More data that can be exchanged between the running project and TMQTT Broker. Some examples can be seen below.

...

Info

The client is case-sensitive. If the topic is not fetching data, check for possible typos in the subscribed topics.


Step 4: After subscribing for to the desired topics, the exchanged data can be seen in the top right corner.

...

Code Block
{
"timestamp": 1580152490182, "metrics": [
{
"name":  "Integer1", "timestamp": 1580152489659, "dataType": "Int32", 
"value": 30
}
],
"seq": 1
}

Appendix

MQTT

As defined in http://mqtt.org/:

”MQTT is a machine-to-machine (M2M)/”Internet of Things” connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport. It is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium. For example, it has been used in sensors communicating to a broker via satellite link, over occasional dial-up connections with healthcare providers, and in a range of home automation and small device scenarios. It is also ideal for mobile applications because of its small size, low power usage, minimized data packets, and efficient distribution of information to one or many receivers (more...)”.

Sparkplug B

As defined in https://www.bevywise.com/blog/sparkplug-b-mqtt-simulation/.

...