All Products
Search
Document Center

ApsaraMQ for MQTT:Query the connection history of a device

Last Updated:Aug 12, 2026

When a device disconnects unexpectedly, use Device Trace Query (also known as Log Retrieval) 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. Common triggers include a client process crash or forced termination (for example, kill -9), or an internal MQTT SDK exception that closes the TCP connection abnormally. Check the client logs to confirm the disconnection timestamp and whether the client process exited abnormally.
Socket IOExceptionConnection closed. Network jitter or packet loss broke the TCP connection. Common triggers include a brief interruption of the client's local network, or a firewall or proxy server that blocks the MQTT connection. Check the client's network connectivity and confirm that firewall and security group rules allow traffic on the MQTT ports (1883 for TCP and 8883 for TLS).
invalid paramConnection closed. The request contained invalid parameters.
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 empty query results

An empty query result means the device has no connection records within the selected time range. Troubleshoot the issue using the following steps:

  1. Confirm whether the device has ever initiated a connection request — Subscribe to online/offline notifications through rule management to monitor the device's connection status in real time.

  2. Check the network on the device side — Verify that the device can access the ApsaraMQ for MQTT endpoint domain, and check whether firewall rules allow the connection.

  3. Check the authentication information — Verify that the token or certificate has not expired or been misconfigured.

  4. Check the reconnection logic — Verify the device's reconnection interval and maximum retry count.

  5. Confirm the time range — The maximum query time span is one day. Make sure the selected time range covers the period when the device may have connected.

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, including an internal MQTT SDK exception.

  • The client process was forcefully killed, for example, by running kill -9.

Inspect the client application logs to confirm the disconnection timestamp and whether the client process exited abnormally.

Note

Network-level interruptions, such as a transient network outage or a firewall that blocks the connection, are reported separately. See the Network jitter or packet loss section below.

Network jitter or packet loss

Indicator: Socket IOException

Network jitter or packet loss between the client and the broker broke the TCP connection. Possible causes:

  • A transient network outage on the client side, such as an operating system-level network interruption caused by a NIC failure.

  • A firewall or proxy server that blocks the MQTT connection.

Verify that the client can reach the ApsaraMQ for MQTT endpoint, and confirm that firewall and security group rules allow traffic on the MQTT ports (1883 for TCP and 8883 for TLS).

Invalid request parameter

Indicator: invalid param

The connection was closed because the client sent a request that contains an invalid parameter. Check the connection parameters on the client against the protocol requirements and correct any invalid values.

Broker maintenance

Indicator: ServerShutdown

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

Related topics