On this page
MQTT collection client
The MQTT Collection Client subscribes to broker topics and maps fields from valid JSON messages to gateway variables. RawString controls write publishing; it does not enable telemetry mapping from arbitrary non-JSON text.
Compatible devices and models
| Device series / model examples | Connection requirements |
|---|---|
| Devices or platforms publishing messages over MQTT | The gateway connects to an MQTT broker. Match topics, QoS and payload mapping to the publisher. |
Connect the broker and publisher
The MQTT collection client connects to a broker and maps JSON payload fields to gateway variables. Publishers may be equipment, another gateway, or an application. PLC rack, slot, and register numbers do not apply.
Obtain the broker host, listening port, MQTT version, credentials, and topic permissions. The gateway and publisher must use the same broker. The gateway account needs permission to subscribe to telemetry and, for control variables, publish to control topics. 127.0.0.1 refers to the computer running each program; use the broker’s reachable interface address across computers.
This example uses 127.0.0.1:18883 and telemetry/line1. The MQTT collection server can provide this listener.
- Create an MQTTX connection named
Collect_MQTTX:mqtt://, host127.0.0.1, port18883, Client IDcollect-mqttx, MQTT3.1.1. Match credentials and SSL/TLS to the broker, then connect.

Open the complete MQTTX connection window. Give MQTTX and the gateway different Client IDs; duplicate IDs can disconnect each other.
- Open Development Configuration → Collection Configuration → Add Device, and select MQTT Collection Client. This plugin owns its connection; do not create an ordinary TCP or serial channel. The device execution interval can remain
1000ms. Telemetry updates when messages arrive, independently of that interval.

- In Plugin Properties, select
Tcp,127.0.0.1, port18883, Client IDcollect-gateway-client, MQTT 3.1.1, and QoS0. Save and enable the device.

Enter the broker host without a port in IP address:

Plugin properties
Connection
| Setting | Description |
|---|---|
| Connection type | Default Tcp. Use WebSocket only for a broker endpoint providing MQTT over WebSocket. An HTTP management console is not an MQTT endpoint. |
| IP address | Default localhost. Broker IP or host name without scheme, port, or path. Use a reachable address for a remote broker. |
| Port | Default 1883. Match the actual broker listener, including its TLS or WebSocket port. The example uses 18883. |
| WebSocket path | Default /mqtt; used only for WebSocket. Empty uses /mqtt, and a missing leading slash is added. Match the broker and proxy path. SSL changes the scheme to wss://. |
| Client ID | Empty by default, producing a random identity that can change when the connection instance is rebuilt. Use a stable, unique ID for persistent sessions and ID-based authorization. |
| Clean session | Enabled by default. Requests a clean session. When disabled, use a stable Client ID and check the broker’s session policy. This setting does not make telemetry retained. |
| MQTT version | Default MQTT 3.1.1; options are 3.1, 3.1.1, and 5.0. Match the broker. Start with 3.1.1; if a 3.1 connection fails, use mutually supported 3.1.1 or 5.0. |
TLS and authentication
| Setting | Description |
|---|---|
| Enable SSL | Disabled by default. Enable for a TLS or WSS broker listener and use its matching port. |
| SSL target host | Empty by default. Host name expected in the broker certificate; configure the certificate name when connecting through an IP address. |
| Client certificate | Select a client certificate with its private key from Certificate Management when the broker requires mutual TLS. |
| CA certificate | Select the CA used to trust the broker certificate. Import the required private root or intermediate CA first. This is separate from the client identity. |
| Allow untrusted certificate | Enabled by default. Disable when validating broker identity and configure the correct CA and target host. This cannot correct a wrong port, account, or topic permission. |
| SSL protocol | Default System Default negotiates TLS through the operating system when SSL is enabled. Explicit TLS 1.2/1.3 requires support at both ends and in the OS. Legacy Default is the SSL 3.0/TLS 1.0 combination. |
| Check certificate revocation | Disabled by default. Requires access to the relevant certificate status service when enabled. Disabling this does not disable certificate-chain validation. |
| Username | Empty by default. MQTT account assigned by the broker, separate from Client ID. Grant the account the required topic permissions. |
| Password | Empty by default. Password for the MQTT account. Account and certificate authentication are separate checks. |
Runtime and messages
| Setting | Description |
|---|---|
| Keep-alive | Default 60 seconds. Maintains the MQTT session and must fit broker policy; it is not the telemetry update interval. |
| Connection timeout | Default 3000. This setting does not adjust the MQTT handshake timeout for this plugin; use device logs to diagnose actual connection failures. |
| QoS | Default 0, used for subscription requests and plugin publishes. 0: at most once; 1: at least once; 2: exactly once. Handle duplicates at the application level when using QoS 1. |
| Detailed log | Disabled by default. Enable for connection, topic, and payload diagnosis; disable afterward to reduce logging. |
| Check and cleanup interval | Default 60000, in seconds. A readable variable becomes offline after this time without a sample and recovers with a new valid message. Set the permitted missing-sample duration, for example 5 seconds. This does not clean disk caches. |

QoS 2 subscription acknowledgements can currently be treated as failures, affecting the confirmed subscription list and RPC readiness. Use QoS 0 or 1 when subscription confirmation is required. Protocol delivery confirmation does not establish remote equipment execution.
Map a variable and compare messages
- Add
MQTT_Client_Temperatureto the device. ChooseInt16, Read only, and array length1for this single integer. Array length is neither a topic count nor a JSON character count. Use a floating-point, Boolean, or string type for the corresponding payload; useObjectfor a complete object.


- Open Variable Address → Edit fields. Enable Subscribe topic and JSONPath, entering
telemetry/line1and$.data.value. Leave explicit null, condition, publish, and RPC fields unchecked. Click Confirm and fill, then save the variable.

The address becomes SubscribeTopic=telemetry/line1;Path=$.data.value;. value is a JSON property, not a PLC byte offset; register word order does not apply. See Collection Configuration for common transforms, alarms, and permissions.
- In MQTTX, publish
{"data":{"value":31}}totelemetry/line1, QoS0, Retain disabled, then click the green arrow at the bottom right of the send area. Publish after saving the variable; an earlier non-retained message is not replayed to a new subscription.


- Open Live Variables → Details and compare current value
31, raw value, and collection time. Change31to32in MQTTX and publish again; the value and collection time should update.

A broker connection can stay online while telemetry stops. The variable then follows the missing-sample interval. Invalid JSON, an unmatched path, or a false condition also prevents a valid new sample.
Write a variable and receive control messages in MQTTX
Collection flows from MQTTX publishing telemetry to a gateway variable. Writing flows from a gateway variable through the broker to a control-topic subscriber. The written value becomes the message body; the plugin does not wrap it in {"data":{"value":…}}. Write the required object directly, or build it with the variable’s write transform chain.
- Click New Subscription in MQTTX. Enter
commands/line1/#, choose QoS0, and confirm.#receives this level and its descendants; the gateway must publish to a concrete topic.

- Add
MQTT_Client_Commandunder the client device:Int16, Write only, array length1. Keep the read-only temperature variable separate.


- Open Edit fields. Under Control write, enable Publish topic =
commands/line1/setpoint, Payload mode =Json, and the Retain property with its switch off. Leave telemetry fields, response topic, and timeout unchecked. Click Confirm and fill.

The address is:
PublishTopic=commands/line1/setpoint;PayloadMode=Json;Retain=false- Enable RPC write in the variable’s RPC Configuration, then save. This switch permits writes through the variable write entry. RPC → Response topic in the address editor instead enables waiting for an MQTT peer acknowledgement. Leave the response topic unset for ordinary publishing.

- In Live Variables, click Write on
MQTT_Client_Command, enter42, check that the input is recognized as a number, and submit. Use the command variable’s write action, rather than the temperature variable or the initial-value field.

- In MQTTX, locate topic
commands/line1/setpointwith body42. Check both topic and body. This command does not directly change the value mapped fromtelemetry/line1; the equipment must publish new telemetry for the reading to reflect its resulting state.

Choose JSON values or raw strings
The Write dialog recognizes JSON numbers, Booleans, objects, and arrays; other text is treated as a string. Match the variable type and payload mode to the receiver:
| Required body | Variable type and mode | Write dialog input |
|---|---|---|
JSON number 42 | Int16, Json | 42 |
JSON string "42" | String, Json | "42", including quotes |
JSON Boolean true | Boolean, Json | true |
JSON object {"setpoint":42} | Object, Json | {"setpoint":42} |
Unquoted text RUN | String, RawString | RUN |
Unquoted text true | String, RawString | "true", so the input is recognized as a string |
RawString accepts only a string value and removes its enclosing JSON quotes when publishing. It does not automatically turn a number, Boolean, or object into text. Retain=true stores the last message for later subscribers. This command example uses false; choose retention according to the peer’s control semantics.
Wait for a peer acknowledgement
An ordinary publish returns after sending the message. To wait for the peer’s command result, use {RequestId} as the final level of both request and response topics and set a timeout:
PublishTopic=commands/line1/request/{RequestId};PayloadMode=Json;Retain=false;ResponseTopic=commands/line1/response/{RequestId};Timeout=5000The peer subscribes to commands/line1/request/+. Each write generates a fresh ID. For example, a request on commands/line1/request/abc123 with body 42 requires a reply on commands/line1/response/abc123: {"success":true} or {"success":false,"message":"reason"}. The lowercase success property must contain a JSON Boolean; disable Retain on the reply. Timeout is 100–60000 milliseconds. For a manual MQTTX reply, start with a longer timeout and copy the current request’s final topic level into the response topic. Keep the placeholder in gateway configuration and use the actual ID in the response.
Address rule
Use PropertyName=Value; for each configured property. Property order is unrestricted and names are case-insensitive. Omit unused properties; the final semicolon is optional. Duplicate properties and mixed named/positional fields are rejected.
SubscribeTopic=vendor/device;Path=$.data.temperature;Condition=TelemetryCondition;| Property | Description |
|---|---|
SubscribeTopic | Telemetry subscription topic or filter. Configure together with Path. |
Path | JSONPath into a valid JSON payload. Separate candidate paths with ||. |
Condition | Optional compiled DataTrans script name. The message is accepted only when the script returns true. |
ConditionParameters | Optional JSON object mapping script input names to parameter text. Every value is a string, for example {"Minimum":"12.5"}. |
PublishTopic | Control or RPC request topic. Omit for read-only variables. |
PayloadMode | Json preserves the JSON type; RawString sends unwrapped string text. Default: Json. |
Retain | true or false. Default: false; the Broker determines retention support. |
ResponseTopic | RPC response topic using the same final {RequestId} level as the request. |
Timeout | RPC timeout in milliseconds, 100–60000. Configure together with ResponseTopic. |
Examples:
| Use | Address |
|---|---|
| Read a JSON value | SubscribeTopic=vendor/device;Path=$.data.temperature; |
| Condition with parameters | SubscribeTopic=vendor/device;Path=$.data.temperature;Condition=TelemetryCondition;ConditionParameters={"Minimum":"12.5"}; |
| Publish a raw write | PublishTopic=factory/a/reboot;PayloadMode=RawString;Retain=false; |
| RPC request and response | PublishTopic=factory/a/command/{RequestId};PayloadMode=Json;Retain=false;ResponseTopic=factory/a/response/{RequestId};Timeout=5000; |
Path=$.data.temperature;SubscribeTopic=vendor/device; is equivalent to the first example.
Configure condition parameters in the Web editor
- Open the variable form and click Edit fields beside Variable Address.
- Enter the subscribe topic and JSONPath, enable the condition field, and select a compiled DataTrans script.
- Fill in the inputs shown with their names, types, and descriptions. The order of inputs does not affect their binding.
- Click Confirm and fill, then save the variable. Applying a changed legacy address generates the named format; viewing or cancelling leaves the original text unchanged.
Parameter text is parsed as a JSON value when possible, otherwise as a string, and is converted to the declared input type. Use 12.5 for a number, true for a Boolean, and JSON for an object or array. Strings may be entered directly; use a quoted JSON string such as "true" to preserve a string resembling a Boolean, null, or number. Unknown inputs and invalid types prevent saving. Each variable stores its own parameter values.
Clearing an input removes its explicit override. Unspecified inputs keep their script defaults; Topic, MqttTopic, ClientId, and MqttClientId receive message context when not explicitly configured. The client plugin receives no publisher ClientId, so those inputs are empty.
Only the first = separates a property from its value; JSONPath filters containing == work unchanged. In named address values, encode ; as %3B and % as %25. Values are decoded once and + remains literal. The editor handles escaping automatically. For example, ConditionParameters={"Marker":"a%3Bb%25"} supplies the string a;b%.
Legacy eight-segment addresses
Existing positional addresses remain supported. Keep unused intermediate segments empty and omit trailing empty segments as needed. Use the named format or Web editor to add condition parameters.
{subscribeTopic};{jsonPath1||jsonPath2};{condition};{publishTopic};{Json|RawString};{retain};{rpcResponseTopic};{rpcTimeoutMs}
vendor/device;$.data.temperature;TelemetryCondition
;;;factory/a/command/{RequestId};Json;false;factory/a/response/{RequestId};5000Payload paths support $, dot paths such as items.0.value, filters [?()], wildcards [*] and .*, and recursive search $..name. With ||, the first existing candidate path is used. Exact case-sensitive property names are preferred; a unique case-insensitive match is used only when no exact name exists.
A present field with null does not guarantee fallback to the next path. Multiple JSONPath matches select the first result rather than creating multiple variables. Use Object to retain an object value and check scalar types against the actual payload.
The condition is a DataTrans script name. Its raw input contains the complete JSON payload; it may also declare Topic or MqttTopic to inspect the published topic. A wildcard subscription updates the same variable for every matching message, so use an exact topic or filter by Topic when values must be separated by device.
The subscribed message does not include the publisher’s client ID. ClientId and MqttClientId inputs are therefore empty for this plugin. Publish topics cannot contain + or #; {RequestId} must be the final topic level.
A subscribe topic and JSONPath must be provided together; publish options require a publish topic. RPC response topic and timeout are a pair, and the timeout must be 100–60000 ms. A read-only variable cannot contain publish fields, a write-only variable cannot contain telemetry fields, and every variable must configure at least one route.
Device debug
Open Development Configuration → Collection Configuration, select the MQTT device, open Protocol Debug at the top of the workspace.
Subscriptions and publishing

Use Publish Message to send a small payload to an approved test topic. Subscription management and received-message inspection are available in the corresponding protocol workspace tabs.
Functions
| Function | Purpose |
|---|---|
| Publish message | Publish a topic, payload, QoS, and Retain flag through the current broker connection. |
| Subscription management | Create, refresh, or remove subscriptions and inspect the received updates. |
| Refresh subscriptions | Reload the subscriptions confirmed by the current MQTT session. |
Messages and freshness
- Subscribe to an exact test topic.
- Publish a JSON payload containing one known field.
- Confirm that the JSONPath or condition script selects the expected value.
- Check that the variable value and collection time update.
- Test publishing or RPC only when the variable and device permissions allow it.
Keep the broker connected and stop new telemetry to test freshness. For a short test, set Check and cleanup interval to 5 seconds, wait for the point to become offline, then publish a new valid value and confirm recovery. Restore the production interval afterward. MQTT keepalive maintains a session; it does not establish that a point is receiving fresh data.
For control, enable the variable’s RPC write permission, inspect the exact Topic and raw payload with an independent subscriber, and verify field feedback. Json preserves the input JSON type; RawString accepts only a JSON string and publishes its unwrapped text. For RPC, an old retained response, a different RequestId, or a response arriving after timeout cannot complete the new request.
Enabling Retain stores the last message for later subscribers; it does not store history or confirm command execution. Publishing later with Retain false does not delete an older retained message. Use a fresh test topic or clear the old retained message through the Broker before verifying the disabled setting.
Troubleshooting
| Symptom | Check |
|---|---|
| Cannot connect | Broker address, port, Client ID, credentials, TLS settings, firewall, and broker ACL. |
| Message arrives but variable is unchanged | Exact topic, JSONPath, condition script, payload shape, and variable data type. |
| Wrong device value is updated | Avoid a shared wildcard topic or filter by Topic in the condition script. |
| Publish or RPC fails | Publish topic, {RequestId} position, QoS, response topic, timeout, and permissions. |
| Certificate is rejected | Client certificate, CA, target host name, and trust settings. |
Related links
- Collection Configuration: Devices, variables, common permissions, and import.
- Certificate Management: Manage MQTT client and CA certificates.
- Plugin Manual Index: Other collection and data-forwarding plugins.