Skip to content

MQTT Forwarder

The MQTT Forwarder is a middleware solution designed to enable protocol integration between third-party application platforms and ThinkLink. It achieves this through flexible JavaScript scripting, supporting:

  • Cross-platform message routing (source → target broker)
  • Dynamic topic redirection
  • Message payload format transformation

1. Configuration Workflow

1.1 Step 1: Establish Broker Connections

  1. Prepare broker credentials:

    • ThinkLink Broker credentials: Retrieve from System Configuration → Server Configuration → Internal MQTT. Users may modify these credentials as needed.
    • Third-party broker credentials: Obtain from your broker provider. Required information includes:
      • Username/password
      • TLS certificate (if encrypted connection is required)
  2. Select connection type:

    • Customize: For third-party brokers
    • ThinkLink: Subscribes to topics containing Thing Model–parsed data (e.g., /v32/[tenant]/tkl/up/telemetry/#)
    • AS: Subscribes to raw, unprocessed data (e.g., /v32/[tenant]/as/#)

⚠️ Note 1: At least two broker connections must be configured — one as the source and one as the target.
⚠️ Note 2: [tenant] refers to the organization account of the ThinkLink user.

img

1.2 Step 2: Configure Forwarding Rules

  1. Access the configuration interface: [Advanced Features] → [Forwarder] → [Add New]

  2. Basic Settings:

    • Name the forwarder instance
    • Enable/disable the forwarder via toggle switch
  3. Endpoint Configuration:

    • Source Broker: Select from dropdown (create new if not listed)
    • Target Broker: Select from dropdown (create new if not listed)
    • Subscription Topic: Supports MQTT wildcards (e.g., +/sensor/+/telemetry)

img

1.3 Optional: Protocol Transformation Script

If no custom script is provided, the forwarder relays messages unchanged — preserving both original topic and payload format.

javascript
// Example: Renaming telemetry fields 'T' → 'temperature', 'H' → 'humidity' to comply with another protocol
function forwardScript({topic, msg, org_params}) {
  if (!msg?.telemetry_data) return;
  let content = {};
  content.temperature = msg.telemetry_data?.T;
  content.humidity = msg.telemetry_data?.H;
  return {
    topic: `/v32/test/my/up/gw/${eui}`,
    option: {
      retain: false
    },
    msg: content
  };
}

Input Parameters

ParameterTypeDescription
topicstringThe original subscribed MQTT topic
msgObjectReceived message payload (JSON format)
org_paramsObjectOrganization-level (tenant-level) "environment variables" maintained under System Management → Server Configuration → Org Params. Useful for third-party platform credentials and shared target-topic prefixes. See Server Configuration §1.6.

Return Value

Return a new message object (or null to discard the message):

FieldTypeDescription
topicstringTarget topic — supports dynamic variable substitution using ${variable} (e.g., ${msg.deviceId})
msgObjectTransformed message payload (must conform to the target protocol specification)
optionobjectOptional configuration — e.g., { retain: true } to publish as a retained message

Version History & Restore

Every time you save a forwarder script, the platform records a version snapshot. Click History Versions in the editor to browse earlier versions. Each entry offers:

  • Detail — view the snapshot's content (and compare it against neighboring versions).
  • Restore — roll the current value back to that snapshot. Restoring creates a new version entry (so nothing in the history is lost) and reloads the list to the first page. A confirmation prompt notes that restoring produces a new version.

The same History Versions / Restore controls are available on the RPC Model, Thing Model, and Trigger Model editors.

System Platform and Public Forwarders

Forwarders can now be maintained from the System Platform. Public forwarders created by the system admin are visible on the tenant side, but tenant users cannot edit public configurations.

  • When organization is empty or PUBLIC, ThinkLink clears Source Broker and Target Broker and saves the record as public configuration.
  • When a specific organization is selected, the forwarder can use that organization's brokers and org_params.
  • Subscription Topic is required only after a Source Broker is selected.
  • Source Broker and Target Broker cannot both be AS/ThinkLink types, to avoid meaningless or unsafe internal loops.

Subscription Topic supports ${...} placeholders from organization params.org_params. The script entry point remains forwardScript({topic, msg, org_params}), and org_params is read-only.