MQTT Publisher/Subscriber

MQTT Publisher/Subscriber

1. MQTT Publisher/Subscriber

MQTT is a lightweight message transport protocol that centers on two roles: publisher and subscriber. A Publisher publishes messages to a specific topic, and a Subscriber subscribes to that topic to receive those messages. These two components do not communicate directly, but indirectly through an MQTT Broker in the middle. For example, a temperature sensor periodically publishes data to a topic called β€œhome/temperature”, and a smartphone app subscribes to this topic to receive real-time temperature information. This allows multiple Subscribers to receive messages from one Publisher at the same time, and is widely used in IoT environments because the communication structure is simple and efficient.

Supported devices and requirements

Β 

Description

Notes

Protocol

MQTT

Β 

Driver Description

MQTT Publisher/Subscriber

Β 

Supported Devices

MQTT-enabled devices across the board

Β 

Requirement

MQTT broker required

Β 

2. Comm Settings

You can connect to the equipment to be communicated through I/O device settings. [After selecting [Tools] - [I/O Device] to enter the [I/O Device Settings] screen, press the [New Device] button to move to the [Select I/O Device Type] screen as shown below.

Β 

mq1.PNG
  1. Device Name Enter a name to distinguish the device.

  • Be careful not to use on-dots, dots, spaces, math symbols, or special characters such as double dots (colons) and double half-dots (semicolons) in device names, as they can prevent devices from being created or cause system operational issues.
    ex) Device_Name (O), Device.Name(X)

  • You can't create a device if you don't write a device name, don't select a device type, or write a duplicate device name.

  1. Manufacturer Select the type of device to connect with CIMON-SCADA. In this manual, it is set to Mqtt publisher/subscriber.

  2. Ok After completing all settings, click the [OK] button to register the new device with the entered contents. Clicking the [OK] button will return you to the I/O device settings screen, and you can check the registered device on the returned screen.

  3. Cancel Cancel the action you are performing and exit the selection screen.

Β 

Add Station

A station is a piece of equipment for separating multiple devices (PLCs) connected to the same network. When using a station, each device (PLC) can be set up separately.

Β 

mq_2.PNG
  1. Click Add station to add an MQTT station.

Β 

mq3.PNG
  1. Enter the station name and broker address, and press OK to add the station.

Β 

mq4.PNG
  1. You can see that the station has been added. You can modify the station settings by tapping Edit.

Β 

Station Setting

mq5.PNG

Β 

Β 

λ‚΄μš©

Common Options

Station

This is the name of the station and can only be named when adding it.

Broker Address

The broker address is the IP address or domain name of the target server that MQTT clients will contact to send and receive messages. Because MQTT communication is centered around a centralized broker, clients must attempt to connect through that broker's address. For example, a public broker for testing might be broker.hivemq.com or test.mosquitto.org, while an internal IP or domain address would be used for an internal system.

Client ID

A client ID is a unique identifier to distinguish a device or application connecting to an MQTT broker. Each client must have a different ID, and using duplicate IDs can cause existing connections to be dropped or new connections to be denied. Client IDs are typically set using sensor names, device identifiers, UUIDs, and so on, and some brokers automatically generate a random ID if the client ID is left blank.

Keep Alive

Keep Alive is the time interval (in seconds) that an MQTT client sets to ensure that its connection to the broker is still alive and well. The client must send a message to the broker at least once during this time, and if it has no actual message to send, it will send a PINGREQ packet instead to maintain the connection. If no communication occurs for the set amount of time, the broker can assume that the client has abnormally disconnected and terminate the session. For example, if the Keep Alive value is set to 60, the client must signal the broker at least once every 60 seconds, which is important for network health detection and client health monitoring.

Use Passwords

Check Enable password.

User Name

Your username is part of the credentials you use to request authentication from an MQTT broker. When the broker requires authentication, the connection is allowed only if the correct username is provided. This is primarily a security measure to prevent external intrusion and control client-specific access, and can be omitted depending on your setup.

Password

The password is used in conjunction with the username to perform authentication to the MQTT broker. Because passwords can be transmitted over the network, it is common for them to be accompanied by encrypted communication (TLS). The username and password must be pre-registered on the broker's side, and if incorrect information is entered, the connection is rejected.

Description

Enter a station description.

Subscriber Option

QOS

QoS is a setting that defines how reliably MQTT messages are delivered between the broker and client, and has three levels (0, 1, and 2). QoS 0 is β€œmaximum once delivery,” which is the fastest but can result in lost messages because messages are sent only once and never checked for receipt. QoS 1 is β€œdeliver at least once,” which means that messages are delivered at least once by repeating retransmissions until an acknowledgment of receipt (PUBACK) is received, but there is a possibility of duplicate receptions. QoS 2 guarantees β€œexactly once delivery,” which requires the most network traffic and overhead, but delivers messages most reliably without duplication. Depending on your intended use, you should set the QoS level based on a balance between performance and reliability.

Β 

Retain

Retained Message is a feature that allows an MQTT broker to β€œkeep” the last received message in its topic, so that it can be immediately delivered to clients who subsequently subscribe to it. Normally, MQTT only delivers messages to subscribers who were subscribed to the topic at the time of publication, but retained messages allow new subscribers to immediately receive the most recent status information. For example, if a temperature sensor publishes the current temperature to a topic called β€œhome/temperature” as a retained message, apps or devices that subsequently subscribe to the topic for the first time can get the latest temperature value first, even before real-time data is available. This feature is useful for communicating status information or initialization messages, but should be used in context as it can provide unnecessary outdated information.

Use All Tag

When checked, publish all tags in SCADA. When unchecked, it will only publish the listed tags.

Add Tag

You can uncheck all tags and add only the tags that need to be published.

Delete Tag

Delete from the Publish tag list.

Β 

Publisher

You can subscribe to tags in SCADA PRO on other devices by registering tags to publish.

Β 

mq5.PNG
  1. Register the tags you want to publish as shown above. If you check All tags, all tags in the project will be published. Depending on the amount of tags, it may cause process load, so please test before using it.

Β 

P-1.PNG
  1. You can use a test program like MQTTX to check the values of the tags you've set up in Publish.

Β 

Subscriber

You can subscribe to the topics you need from external MQTT devices. See an example of configuring the subscribe feature below.

Β 

  1. Publish directly to the JSON data format with the test program MQTTX.

Β 

mq6.PNG
  1. Set up the device and address as shown above.

  • Device registration in the Tag settings is the same as for other drivers.

  • The address registration is in the format β€œtopic#/jsonkey”, with topic and key separated by #.

Β 

ex)

{
Β Β "msg":Β "arr_0",
Β Β "arr":Β ["one",Β "two"]
}

"msg":Β To get the value β€œarr_0”, you can enter a key like β€œtopic#/msg”.

s2.PNG

β€œarr”: [β€œone”, β€˜two’] To get the array values, you can enter β€œtopic#/arr/0”, β€œtopic#/arr/1”.

If you just enter β€œtopic#”, you will get it in rawdata format with stirng tags, which you can also parse with a script.