All Products
Search
Document Center

ApsaraMQ for MQTT:Query the connection history of a device

Last Updated:Mar 11, 2026

When a device disconnects unexpectedly, use Device Trace Query to review its connection history. The query results show each connect, disconnect, and close event with a detailed reason, helping you pinpoint why the connection dropped.

Prerequisites

Before you begin, make sure that you have:

  • A running ApsaraMQ for MQTT instance

  • The Group ID and Device ID of the target device

Query device connection events

  1. Log on to the ApsaraMQ for MQTT console. In the left-side navigation pane, click Instances.

  2. In the top navigation bar, select the region where your instance resides. Click the instance name to open the Instance Details page.

  3. Find the instance that you want to manage. In the Actions column, choose More > Device Trace Query.

  4. On the Device Trace Query page, specify the Group ID, Device ID, and Time Range, then click Search.

    Note

    The maximum query time span is one day.

Query results

The query returns a table with the following columns:

ColumnDescription
Channel IDThe connection ID.
Device ActionThe type of connection event. See the Device actions section below.
Action DescriptionThe reason or outcome of the event. See the Action descriptions section below.
TimeThe timestamp when the event occurred.

Device actions

Each device action represents a stage in the MQTT connection lifecycle:

ValueMeaningLifecycle stage
connectThe client sent a CONNECT request to the broker.Connection initiation
closeThe TCP connection was closed.Connection termination (passive)
disconnectThe client sent a DISCONNECT request to the broker.Connection termination (active)

Action descriptions

Each action description explains why the connection state changed:

ValueMeaning
acceptedThe broker accepted the client's connection request.
not authorizedConnection closed. The client failed permission verification to access the instance.
topic auth failedConnection closed. The client failed permission verification to access topics.
clientId conflictConnection closed due to a conflict in the client ID.
no heartConnection closed. The broker detected no heartbeat from the client.
closed by clientConnection closed due to a client-side exception. The client did not send a DISCONNECT packet.
disconnected by clientThe client initiated a graceful disconnection by sending a DISCONNECT packet.
ServerShutdownConnection closed. The broker was upgraded or went offline for maintenance.

Troubleshoot disconnections

Use the Action Description value to identify the root cause of a disconnection:

Permission verification failure

Indicators: not authorized, topic auth failed

Verify that the client credentials are correct and that the client has the required permissions for both the instance and the target topics. Check the following:

  • The client credentials are valid and not expired.

  • Topic permissions are granted for the specific topics the client subscribes to or publishes to.

Client ID conflict

Indicator: clientId conflict

Two clients sharing the same client ID cannot maintain simultaneous connections. To resolve this:

  • Make sure each client uses a unique client ID.

  • Check for duplicate deployments or misconfigured device provisioning that may assign the same ID to multiple devices.

Heartbeat timeout

Indicator: no heart

The broker closes the connection if it receives no heartbeat from the client. Possible causes:

  • Network instability prevents heartbeat packets from reaching the broker.

  • The client process is blocked or overloaded, preventing timely heartbeat transmission.

Unexpected client-side closure

Indicator: closed by client

The TCP connection was terminated without the client sending a DISCONNECT packet. This typically indicates:

  • A crash or unhandled exception in the client application.

  • An operating system-level network interruption (e.g., a firewall rule change or NIC failure).

  • The client process was forcefully killed.

Inspect the client application logs and system-level network logs to identify the cause.

Broker maintenance

Indicator: ServerShutdown

No action required. The broker closed connections during a scheduled upgrade or maintenance window.

Related topics