Skip to main content

Data Export by MQTT

You can use the MQTT broker built into Aqara Studio, or integrate your own MQTT broker, to forward device data to third-party platforms so they can query and control connected devices.

tip

This guide uses the MQTTX desktop app to show how to connect to MQTT and how to subscribe to and publish messages.

What can you do with MQTT export?​

With MQTT export, you can call the JSON business APIs enabled for MQTT, subscribe to or unsubscribe from device data, and receive data changes and other events. The application-level ping renews subscriptions; it is separate from the MQTT protocol heartbeat that maintains the Broker connection.

For the JSON objects used in the request and response bodies of these features, see Aqara Developer Studio Local Development - MQTT.

Local MQTT Broker and MQTT Export​

FeaturePurposeRequires the MQTT Export plugin
Local MQTT BrokerProvides MQTT access for LAN devices and applicationsNo; managed independently on supported devices
MQTT ExportStudio connects to the selected Broker as an MQTT client to handle API requests and push subscribed dataYes

The two enable settings are saved separately. Enabling, disabling, or uninstalling MQTT Export does not start or stop the local service. The local service can run for LAN devices while export connects to a third-party Broker. One MQTT Export instance connects to one selected Broker at a time, rather than exporting through both Brokers simultaneously.

The local service card appears only on devices with the required runtime installed. A typical Windows development environment without that service will not show the card. If you only need the local Broker for LAN clients, skip the plugin installation and export steps below.

Install the Plugin​

Refer to the Plugin Market documentation:

  1. Go to Aqara Builder Lab - Marketplace and get the MQTT Export plugin.
  2. Assign it to Aqara Studio.
  3. In Aqara Studio, open Plugin Center and install the MQTT Export plugin.

Enable the MQTT Export Service​

  1. In the left sidebar of Aqara Studio, open Plugin Center, find the MQTT Export plugin, and click Transfer Out.

    Find the MQTT Export plugin in Plugin Center and click Transfer Out

  2. You are taken to the Developer page. Enable MQTT transfer out.

    Enable the MQTT export service

Choose a Broker​

Choose a Broker that fits your setup:

Use the Local MQTT Broker​

  1. Enable the separate Developer → Local MQTT Broker service and wait for Running. Studio confirms that the port shown on this card is reachable during startup before reporting Running. Use the displayed port; do not assume it is always 1893.
  2. LAN clients connect using the card's LAN address, port, username, and password. These settings are managed by Studio and are read-only. Use the copy icons beside the username and password to copy their full values. Users with write permission can reveal the password while the service is running.
  3. To export Studio data, enable MQTT Export and select Local MQTT Broker. Connection settings are supplied automatically, and Studio connects once the local service is ready.
StatusMeaning and action
Local service startingWait for startup and listener readiness
Local service start or stop failedClick Retry on the local service card to repeat the action matching its enable setting
Export waiting for Local MQTT BrokerExport is enabled, but the local service is not ready; check its separate card
Local service running, export connection failedClick Retry in MQTT Export; service readiness and an authenticated MQTT connection are separate states

Stopping the local service disconnects all clients using it. Export through that service waits and connects automatically when the service starts again. Export through a separate third-party Broker is unaffected. Disabling MQTT Export leaves the local service available to other LAN clients.

The local enable setting and credentials survive Studio restarts. An enabled local service restarts, and enabled local export connects once the service is ready. Running reflects the startup listener check, rather than continuous MQTT health monitoring. Check both service and export status when investigating a connection problem.

Use a Third-Party Broker​

To use a third-party MQTT Broker:

  1. Select Third-party Broker and fill in the following:

    NameDescription
    HOSTBroker IP address or domain name, without a mqtt:// or mqtts:// scheme prefix.
    PortPort number of the third-party MQTT Broker.
    Client IDThe unique client identifier Aqara Studio uses to connect to this Broker.
    UsernameUsername required to connect to the third-party MQTT Broker.
    PasswordPassword required to connect to the third-party MQTT Broker.
    Enable TLSWhether to connect over TLS. Studio chooses the transport; HOST still contains only an IP address or domain name.

    This Client ID identifies Studio's own connection. Do not reuse it for another device or MQTTX connection, because the Broker may disconnect the existing client. The third-party password is saved on blur and then masked with placeholder dots. Use the eye icon to read its full value; the dots are not the password. Credential copy buttons are provided on the local Broker card only.

  2. Configure TLS for the Broker's authentication method:

    AuthenticationRequired filesFile extensionsDescription
    One-wayNo certificate import on this page—Enable TLS to validate the Broker certificate using system-trusted CAs.
    Mutual (two-way)CA certificate
    • .pem
    • .crt
    • .cer (X.509)
    Import all three files. The private key must be PKCS#8 PEM, beginning with BEGIN PRIVATE KEY or BEGIN ENCRYPTED PRIVATE KEY. Save the private key password for an encrypted key.
    Client certificate
    Client private key
    • .pem
    • .key
    If the private key is encrypted, enter the private key password.
    tip
    • The current page does not support one-way authentication with only an imported custom CA. Imported certificate settings require a CA, client certificate, and client private key together; an incomplete set disables Connect. A complete set automatically uses TLS.
    • Clearing an imported certificate only removes the reference. It does not delete the certificate file.
    • If you upload a new certificate, disconnect and connect again for it to take effect.
    Upload certificates
  3. If your platform requires fixed addresses, save both Subscribe topic (Studio receives requests) and Publish topic (Studio responses and push messages) under Fixed Topics. Set both fields or leave both blank. Configured names are used without appending a clientId. See Fixed Topics for a Third-party Broker. Changing and saving the pair disconnects the old connection; reconnect and resubscribe afterwards.

  4. Open the ... menu and select Connect. Studio's account needs subscription access to the request topic and publication access to the response topic. A rejected subscription during connection setup also results in Connection Failed.

    Connect to a third-party Broker

Switching export targets disconnects the old connection and removes its subscriptions without changing the local service enable setting. Third-party configuration is retained. Switching back to third-party mode, editing connection parameters, restarting Studio, or losing the third-party connection requires manual ... > Connect, followed by data resubscription.

Test the MQTT Broker Connection​

tip
  • Before you start, download and install the MQTTX desktop app, or another MQTT client.
  • The steps below use MQTTX as an example. For other MQTT clients, see their official documentation.
  1. For the local Broker, copy connection information from the separate Local MQTT Broker card. For a third-party Broker, use the credentials and unique Client ID assigned to your application by that platform. Application credentials may differ from Studio's; each account needs its own appropriate topic permissions.

    Check the active request and response topics at the bottom of MQTT Export.

  2. Follow the official MQTTX doc Getting Started - Connect, and use the information from the previous step to make the MQTT connection.

    Connect via MQTT

  3. After you connect, click New Subscription.

    New subscription

    In default mode, replace {clientId} in the response topic with this MQTTX connection's actual Client ID. In fixed mode, subscribe directly to the configured Publish topic without replacing placeholders or appending an ID.

    Set QoS to 1, then click Confirm to create the subscription.

  4. In default mode, replace {clientId} in the request topic with the same MQTTX Client ID. In fixed mode, publish directly to the configured Subscribe topic. Use QoS 1 with Retain disabled. Subscribe to the response topic before sending requests.

    Write a JSON message using the request parameters for each API in Aqara Developer Studio Local Development - MQTT, then send it to get a response.

    Start with the subscribe to all device data example. Confirm that the response echoes the request msgId with code: 0, then check live pushes.

Only clients with active subscriptions need periodic application-level ping. Send it at least every 30 seconds when there are no other requests; receiving pushes does not renew the lease. Resubscribe after a connection loss or session expiration. See Heartbeat and subscription lease renewal.