1. Introduction
MQTT is a lightweight, simple, and effective communication protocol that facilitates communication between Internet of Things (IoT) devices. It is widely adopted in various IoT applications. MQTT operates on a Publish/Subscribe model. A Publisher disseminates information on a specific Topic, and a Subscriber can receive related information by subscribing to that topic. When a Publisher sends a new message, the Broker (acting as a middleman) forwards the message to all Subscribers subscribed to that topic. Subscribers can then receive different messages based on their subscriptions.
Diagram Description: Illustrates the MQTT Publish/Subscribe model. A Publisher sends a 'Package' to a 'Broker'. The Broker then forwards this package to 'Subscribers' based on their subscriptions to 'Topic A' or 'Topic B'. A note indicates that subscribers must subscribe before receiving messages.
2. Scenario
Given the prevalence of numerous MQTT platforms with varying formats, Delta HMI has developed a method to interpret MQTT packets, enabling users to define their own data structures. This article utilizes DOP-3S10S3E2 as the Publisher, DOP-3S07S3E2 as the Broker, and a PC running MQTT software as the Subscriber.
3. Hardware/Software Configuration
Hardware:
No. | Device | Type | Quantity |
---|---|---|---|
1 | PC | Windows 10 Enterprise version 22H2 | 1 |
2 | HMI*2 | DOP-3S07S3E2 DOP-3S10S3E2 | 1 |
3 | Cable | RJ45 | 1 |
Software:
No. | Device | Type | Quantity |
---|---|---|---|
1 | MQTT | Version 1.10.1 | 1 |
2 | HMI editing software | DIAScreen | 1 |
Software version: DIAScreen 1.4.2.41 or above
Firmware version: Ver-1.0132.6.1 or above
MQTT Client software: Recommended to use MQTT.fx v1.7.1
MQTT.fx download: https://www.softblade.de/download/
Architecture Description: A network diagram illustrates the setup. DOP-3S10S3E2 (MQTT Publisher) with IP 192.168.123.154 and DOP-3S07S3E2 (MQTT Broker) with IP 192.168.123.155 are connected via RJ45 to a switch (交換機). A PC (MQTT Subscriber) with IP 192.168.123.30 is also connected to the switch, forming a Local Area Ethernet.
4. Operational Steps
This section details how the HMI communicates using the MQTT protocol with MQTTX, displaying custom JSON formats. The setup involves DOP-3S10S3E2 as the Publisher, DOP-3S07S3E2 as the Broker, and a PC's MQTTX as the Subscriber.
Wiring
The MQTT communication protocol is based on TCP/IP. Publishers, Brokers, and Subscribers can exchange data via IP as long as they are within the same network domain. This example connects the Publisher (DOP-3S10S3E2), Broker (DOP-3S07S3E2), and Subscriber (PC) using an RJ45 network cable to implement the MQTT function.
Diagram Description: Similar to the architecture diagram, this shows DOP-3S10S3E2 (MQTT Publisher, 192.168.123.154), DOP-3S07S3E2 (MQTT Broker, 192.168.123.155), and PC (MQTT Subscriber, 192.168.123.30) connected via RJ45 and a switch within a Local Area Ethernet.
Create Broker project (DOP-3S07S3E2)
1. Set Broker information: Open DIAScreen and configure the HMI as an MQTT Broker.
Description of DIAScreen Interface: Shows the MQTT settings window for configuring the HMI as an MQTT Broker. Key settings include enabling the Broker server, specifying a Broker name, and setting the Port to 1883.
Set the HMI IP (MQTT Publisher/Broker/Subscriber must be in the same domain).
Description of HMI IP Settings in DIAScreen: Displays the communication settings for the HMI. Users can set the HMI IP address (e.g., 192.168.123.155), Subnet Mask, Default Gateway, and DNS Server IP address.
Create Publisher project (DOP-3S10S3E2)
1. Set Broker connection settings: Configure the IP address and Port of the Broker to which the publisher will connect.
Description of DIAScreen Interface for Broker Connection: Shows the MQTT settings for connecting to a Broker. Users input the Broker's IP/URL (e.g., 192.168.123.155) and Port (1883).
2. Set Publisher related settings: For the theme setting "TEST_TOPIC", configure the sampling method to "Numerical Variation" and the content format to "JSON Advanced".
Description of MQTT Publisher Property Settings: Displays the configuration for the MQTT Publisher. Users set the Topic to "TEST_TOPIC", the Sampling Method to "Numerical Variation", and the Content Format to "JSON (Advanced)".
Set the information to be sent in Content Settings as follows:
Description of MQTT Publisher Property Content Settings: Shows a table for defining the data payload. Columns include Name, Payload, Type, Object, Array, Value, Address, Address Type, and Length. Example entries include data for "Array1.1.1" (Type: Array, Address: $1, Type: UInt16, Length: 1), "Array2" (Type: Array, Address: $2.0, Type: Boolean, Length: 1), "Array3" (Type: Array, Address: $3, Type: UInt16, Length: 1), and "Value" (Type: String, representing a timestamp).
Create the following components:
- Numeric input component: Write memory address $1, numerical format Unsigned Decimal, length 1 word.
- Alternate button component: Write memory address $2.0.
- Numeric input component: Write memory address $53, numerical format Unsigned Decimal, length 1 word.
Set the HMI IP (MQTT Publisher/Broker/Subscriber must be in the same domain).
Description of HMI IP Settings for Publisher: Shows the communication settings for the HMI, specifically setting the HMI IP address (e.g., 192.168.123.154), Subnet Mask, Default Gateway, and DNS Server IP address.
Description of HMI Screen Components: Displays a preview of the HMI screen showing input fields labeled W:$1, W:$2.0, and W:$3, each with an associated input box.
Create MQTTX project
1. Set the Broker settings (IP and Port) you want to connect to.
Description of MQTTX Connection Settings: Shows the MQTTX application interface for setting up a connection. Users configure General settings including Name (e.g., TEST_JSON), Client ID, Host (e.g., 192.168.123.155), and Port (1883).
2. Click Connect to connect to the Broker and follow the steps below to view Subscriber subscriptions.
3. After clicking Connect, click New Subscription to set the topic for subscription.
Description of MQTTX New Subscription: Shows the interface for creating a new subscription in MQTTX. Users specify the Topic (e.g., TESTTOPIC) and QoS level (e.g., 0).
Function Testing
Enter 50 for $1 (topic variable address) to trigger $2.0, and enter 100 for $3. The packet display content after parameters have been changed three times is as follows:
Description of JSON Output (Test 1): Displays the JSON data received after the first test. It includes "Array1" with a value of 1, "Array2" with a value of false, "Array3" with a value of 0, and a "Value" field showing a timestamp "2024-08-28 13:52:06".
Description of JSON Output (Test 2): Displays the JSON data received after the second test. It includes "Array1" with a value of 1, "Array2" with a value of true, "Array3" with a value of 0, and a "Value" field showing a timestamp "2024-08-28 13:53:00".
Description of JSON Output (Test 3): Displays the JSON data received after the third test. It includes "Array1" with a value of 1, "Array2" with a value of true, "Array3" with a value of 100, and a "Value" field showing a timestamp "2024-08-28 13:53:29".
5. Functions Description (MQTT Advanced Function)
Description of MQTT Publisher Property Table: Shows a table detailing various functions for configuring the MQTT Publisher. Columns include Name, Payload, Type, Object, Array, Value, Address, Address Type, and Length.
No. | Description | Functions |
---|---|---|
[Icon 1] | Add new object | Add a new data object. Supports multiple data formats (numerical, Boolean, string). Data is enclosed in curly brackets { }. |
[Icon 2] | Add new general array | Add a new data array. Supports multiple data formats. Data is enclosed in square brackets [ ]. |
[Icon 3] | Add value/ Boolean array | Add a new numerical/Boolean array. Data is enclosed in square brackets [ ]. |
[Icon 4] | Add value | Add string, quantity, or Boolean values.
|
[Icon 5] | Delete | Delete the selected field. |
[Icon 6] | Edit | Modify selected fields. For objects or arrays, only the name can be changed; parameters can be modified based on value. |
[Icon 7] | Copy | Copy the selected fields. |
[Icon 8] | Paste | Paste the previously copied portion into the selected field. |
[Icon 9] | Template | Paste JSON data format here; the software automatically organizes it into the correct JSON structure, saving time and customization costs. |
[Icon 10] | Preview | Convert the set format into actual JSON data. |
6. Conclusion
This article has demonstrated the architecture of using DOP-3S10S3E2 as the Publisher, DOP-3S07S3E2 as the Broker, and a PC's MQTTX as the Subscriber. It also introduced methods for customizing advanced functions of the MQTT JSON data format.
Architecture Description: Reiteration of the network setup showing DOP-3S10S3E2 (MQTT Publisher), DOP-3S07S3E2 (MQTT Broker), and PC (MQTT Subscriber) connected via RJ45 and a switch within a Local Area Ethernet.
Project files mentioned include: Broker_3S07S3E2_Publisher_3S10S3_1.4.3.45_Json.dpa
and E2_1.4.3.45_Json.c
.