MQTT connection issues

Updated at:

This topic describes how to troubleshoot MQTT connection drops.

How do I set a device heartbeat in IoT Platform?

For more information about MQTT keepalive, see MQTT keepalive.

Can I configure MQTT connection parameters in IoT Platform?

Yes, you can. For descriptions of MQTT connection parameters, see MQTT over TLS, MQTT over WebSocket, and MQTT over IPv6.

Why does my device repeatedly go online and offline?

If a device repeatedly goes online and offline, it is likely because the same device certificate is used to authenticate multiple devices. For example, two devices use the same device certificate. Device 1 goes online first, and then Device 2 goes online. When Device 2 authenticates its connection, the system drops the connection for Device 1. Device 1 then tries to reconnect, which drops the connection for Device 2. This creates a loop. You can use Simple Log Service to query logs based on device information.

A single device can make a maximum of five connection requests per minute. Connection requests that exceed this limit are rejected.

How can I determine why a device was disconnected?

If the device did not actively disconnect, you can check the device logs to find the cause.

If you see a log entry similar to Keepalive timeout after xx seconds, it means the device did not send a heartbeat packet to IoT Platform in time. The server tolerates a delay of 5 seconds. If the server still does not receive a ping packet after this period, it closes the connection with the device.

For more information about MQTT keepalive, see MQTT keepalive.

How do I check for network issues?

If your on-premises environment cannot connect to the server, you can check your local network status. Common network check commands include the following:

  • ping ${productkey}.iot-as-mqtt.cn-shanghai.aliyuncs.com: Checks the connection to the IoT Platform server.

  • telnet ${productkey}.iot-as-mqtt.cn-shanghai.aliyuncs.com 1883: Checks the connection to port 1883.

If these checks show no issues but the connection still fails, you can check your local firewall policy. You can use tools such as traceroute and tcpdump to analyze the specific network cause.

In addition to the default MQTT port 1883, you can also try to connect to the MQTT server on port 443. With default firewall settings, port 443 is much less likely to be blocked.