Skip to main content

MQTT Client Forwarding

Purpose

This target connects to an MQTT broker and publishes gateway variables, devices, alarms, and plugin events.

Configure the forwarding group and target through Data Forwarding. This page covers only MQTT target properties, variable-level RPC permission, templates, and MQTT debug actions.

Open the plugin

Open Development Configuration → Data Forwarding and:

  1. Configure and save the forwarding group range, trigger, interval, online filter, and batching.
  2. Add a target, choose MQTT Client Forwarding, and fill in the basic target information.
  3. Open Target properties and configure the MQTT endpoint, security, message topics, scripts, templates, and cache.
  4. Save and enable the group and target, confirm it is online, then use Target debug for publish and subscription checks.

Basic target information

SettingDefaultConfiguration
Group-Select a saved forwarding group.
Target name-Required and unique within the group. Include Broker and environment.
EnableEnabledDisable to stop the MQTT client.
Log levelInfoTemporarily use Debug for connection, subscription, or publish diagnostics.
Start timeout60 secondsValid range is 1 to 3600 seconds.

Target properties

Connection

SettingDefaultConfiguration
Connection typeTcpUse TCP or WebSocket. TLS changes the scheme to ssl or wss.
IP addresslocalhostBroker host or IP without a scheme or port.
Port1883Common TCP port is 1883; TLS often uses 8883; WebSocket uses the Broker's configured port.
WebSocket path/mqttUsed only for WebSocket. It must start with /.
Client IDEmptyEmpty generates a GUID. A fixed ID must be unique on the Broker.
MQTT versionV311 (MQTT 3.1.1)Match the Broker's supported protocol version.
Clean sessionEnabledDisable for a persistent session, if the Broker supports it.
Keep-alive60 secondsKeep Alive interval. Follow the Broker maximum and network policy.

TLS and authentication

SettingDefaultConfiguration
Enable SSLDisabledEnable for TLS and use the Broker's TLS port.
SSL target hostEmptyDNS name in the certificate SAN; empty uses the IP address.
Client certificateEmptySelect a client certificate with private key for mutual TLS.
CA certificateEmptySelect a custom CA when the Broker certificate is not publicly trusted.
Allow untrusted certificateDisabledTemporary self-signed-certificate testing only; keep disabled in production.
SSL protocolNone (system default)Keep system default unless the Broker explicitly requires TLS 1.2 or 1.3.
Check certificate revocationDisabledEnable according to the security policy.
UsernameEmptyBroker username when authentication is required.
PasswordEmptyBroker password; never place it in templates, screenshots, or logs.

Messages and RPC

SettingDefaultConfiguration
QoSAtMostOnce (0)Select 0, 1, or 2 as required by the receiver.
RetainDisabledRetains the last message per Topic; use only for state topics.
RPC write TopicRpcWriteEnter a prefix without + or #. The client subscribes to {prefix}/+ and replies on {prefix}/{requestId}/Response.
Historical-read RPC TopicRpcHistoryEnter a prefix without wildcards. Requests use {prefix}/{requestId} and chunked responses use {prefix}/{requestId}/Response.
Data request TopicEmptyAny message on this Topic publishes the configured variable, device, and alarm snapshots. Empty disables it.
Device Topic templateEmptyEmpty disables device records; otherwise use a fixed Topic or ${field} template.
Variable Topic templateThingsGateway/VariableUse a fixed Topic or ${DeviceName}/${Name} fields.
Alarm Topic templateEmptyEmpty disables alarm records.
Plugin event Topic templateEmptyEmpty disables plugin-event records.
RPC scriptEmptySelect a saved MQTT dynamic RPC script when custom request/response handling is needed.

${field} must be present on the corresponding entity or script result. Topics control routing only; forwarding-group range controls membership.

Target-variable properties

This plugin inherits the optional text fields Data1 to Data10 and adds RPC permission. The variable must already be in the forwarding-group range.

SettingDefaultConfiguration
Allow RPC writeEnabledAllows an external MQTT client to write this variable. Enable only for approved control points.
Data1 to Data10EmptyProject-specific metadata. MQTT does not publish these values automatically; reference them explicitly from a script or upload template.

Data and scripts

SettingDefaultConfiguration
Detail logDisabledEnable briefly to inspect publish payloads or counts.
JSON indentationEnabledDisable to reduce payload size.
Ignore JSON nullsEnabledDisable when null fields must remain.
Device list uploadEnabledPublish devices as a list; disable for one message per device.
Variable list uploadEnabledPublish variables as a list; disable for one message per variable.
Variable dictionary uploadDisabledApplies only to variable-list mode; groups by DeviceName → Name → Value.
Alarm list uploadEnabledPublish alarms as a list; disable for one message per alarm.
Alarm dictionary uploadDisabledApplies only to alarm-list mode; groups by device and variable.
Plugin-event list uploadEnabledPublish plugin events as a list; disable for one message per event.
Entity scriptsEmptySelect saved scripts for device, variable, alarm, or plugin-event entities; script output is used for Topic and payload rendering.

Upload template configuration

For each entity, choose Text or Json and optionally enter a ${field} content template. Empty content uses default JSON serialization. Preview before saving; JSON mode must be valid JSON and Text mode does not add quoting or escaping.

EntityAvailable fields
VariableId, Name, DeviceName, Value, RawValue, LastSetValue, CollectGroup, CollectTime, CreateTime, ChangeTime, IsOnline, DataType, Unit, RegisterAddress, OtherMethod, Description, ProtectType, RpcWriteEnable, Remark1 to Remark5, ValueInited, IsMemory
DeviceId, Name, ActiveTime, DeviceStatus, PluginName, Description, LastErrorMessage, Remark1 to Remark5
AlarmAlarmId, VariableId, Name, DeviceName, AlarmCode, AlarmLevel, AlarmLimit, AlarmText, RecoveryCode, AlarmTime, EventTime, FinishTime, ConfirmTime, ConfirmText, AlarmType, EventType, Remark1 to Remark5
Plugin eventDeviceName, ObjectValue

An entity script changes the object before Topic grouping and template rendering. Keep template fields aligned with the script output. An empty corresponding Topic disables that entity type.

Cache and capacity

SettingDefaultConfiguration
Enable failed-write retry cacheDisabledEnable in production to retain failed publishes in local CacheDB and replay them after recovery.
Cache file maximum rows262144Maximum CacheDB outbox rows; oldest rows are removed after the limit.
Upload chunk size2000Maximum records per write or replay batch.
Memory queue limit100000Maximum in-memory records before handoff to CacheDB; sustained overload can still discard old data.
Filter offline dataDisabledFilters offline variables at dequeue; the forwarding-group filter also applies.
Upload concurrency1MQTT publishes over one connection; keep 1.

Target debug

Open Development Configuration → Data Forwarding, select the forwarding group and target, and open Debug.

MQTT client protocol panel

MQTT Client Forwarding MQTT client protocol panel

Use the plugin-specific panel to publish a test message, subscribe to a test topic, or remove a subscription. The target must be online before protocol operations can run.

Debug checklist

Use a test Topic and small payload. Check connection state, QoS, retain flag, broker response, and message log. Use a separate test topic for RPC writes.

Verify the target

  1. Subscribe on the receiver side before sending a test value.
  2. Change or write one safe variable included in the forwarding group.
  3. Confirm Topic, payload, QoS, retain flag, and message count.
  4. Check the target log for reconnect, authentication, or publish errors.

Troubleshooting

SymptomCheck
No message at the receiverBroker address, port, Client ID, credentials, Topic, ACL, and target online state.
Connection repeatedly dropsKeep-alive, TLS settings, broker limits, firewall, and network stability.
Topic is unexpectedTopic templates, ${key} fields, entity script output, and group alias.
Retained message is unexpectedDisable Retain when the receiver does not need retained state, then clear the old retained message at the broker.
RPC write failsTarget and variable RPC permissions, RPC Topic, payload format, and the variable data type.
Template output is invalidRun template preview and check placeholder names, JSON syntax, and entity-script output.
TLS handshake failsIP, SSL target host, client certificate, CA, SSL protocol, certificate validity, and the allow-untrusted setting.
Failed publishes disappearCheck the failed-write retry cache, CacheDB pending rows, memory queue limit, and cache file maximum rows.