MQTT Connectivity
ProtoTwin Connect supports the MQTT protocol for connection to most PLCs and industrial IoT devices. Both MQTT 3.1.1 and MQTT 5 are supported. Additionally, both secure (SSL/TLS) and insecure connections are supported. Unlike other protocols, MQTT requires a broker to sit between ProtoTwin and any devices.
For low latency communications, it is recommended to run the broker locally rather than using brokers accessible over the internet. For example, you can install the Mosquitto broker on your local machine and use localhost as the host.
Server Configuration
Click the Add Server button in the Servers tab of the IO Browser and configure the server as follows:
- Protocol: Select MQTT from the list.
- Name: Enter a (preferably) unique name, which will be used to identify the server.
- Host: Enter the host address of the broker.
- Port: Enter the port number for the broker (typically 1883).
- Username: Enter the (optional) username.
- Password: Ender the (optional) password.
Save the configuration to add the server.
Adding Tags
Select the server and then click the Add Tag button. Configure the properties for each tag:
- Topic: The topic name for the tag (e.g. “motor/position”).
- Data Type: The data type for the tag.
- Method: Select publish to write/publish the tag value to the broker, and subscibe to read the tag value from the broker.
- Format: The format for the data written/read.
- Qos: The quality of service.
The following formats are supported:
- Text: The tag value is read/written as an ASCII text string.
- Binary (Big Endian): The tag value is read/written as binary with big-endian encoding.
- Binary (Little Endial): The tag value is read/written as binary with little-endian encoding.
The quality of service (QoS) specifies the level of guarantee for message delivery:
- At Most Once (0): No guarantee of message delivery (fastest).
- At Least Once (1): Guarantees message delivery, but the message may be delivered multiple times.
- Exactly Once (2): Guarantees message is delivered exactly once (slowest).
Formatting
Unlike other protocols, MQTT does not define the format of the data sent and received for a given topic. ProtoTwin allows you to select between three possible formats for each tag.
Text
When the tag is published from ProtoTwin to the broker, it is first converted to an ASCII text string. For example, a boolean tag value will be converted to the string "true" or "false". Similarly, when an updated value for the topic is received from the broker, ProtoTwin will expect the value to be a string and will convert the string "true" to the boolean value true, and "false" to false.
Binary (Big Endian)
The tag will be published in the binary format will big-endian encoding. Booleans are converted to a single byte (0x0 and 0x1). Integers are encoded using two’s complement. Floating point numbers are encoded using the IEEE 754 standard.
Binary (Little Endian)
The tag will be published in the binary format will little-endian encoding. Booleans are converted to a single byte (0x0 and 0x1). Integers are encoded using two’s complement. Floating point numbers are encoded using the IEEE 754 standard.