Message Queuing Telemetry Transport (MQTT) is an asynchronous communication protocol based on the TCP/IP protocol stack. MQTT is a lightweight protocol that is used to transmit messages in the publish/subscribe model. MQTT is scalable in unreliable network environments. MQTT is suitable for scenarios in which the storage space of device hardware or network bandwidth is limited. The sender and receiver of a message that is transmitted over MQTT are not restricted by time or space. You can connect a device to IoT Platform over MQTT.
IoT Platform supports device connections over MQTT. Supported MQTT versions include 5.0, 3.1.1, and 3.1. For more information, see MQTT 5.0, MQTT 3.1.1, and MQTT 3.1.
Differences between IoT Platform-based MQTT and standard MQTT
- Supports MQTT messages, such as PUB, SUB, PING, PONG, CONNECT, DISCONNECT, and UNSUB.
- Supports the clean session flag.
- Does not support will and retained messages.
- Supports quality of service (QoS) 0 and QoS 1 messages and does not support QoS 2 messages.
- Does not support QoS settings on subscriber clients. Only the QoS that is specified by publisher clients is valid.
- Supports the synchronous RRPC mode based on native MQTT topics. A server can call a device service and obtain a response at the same time.
Supported MQTT 5.0 features
Compared with the previous version, MQTT 5.0 provides a large number of new features to improve performance and user experience. For more information, see Appendix C. Summary of new features in MQTT 5.0.
IoT Platform supports the following new features of MQTT 5.0:
|Configure the Clean Start feature and the session expiry interval.|
|Specify a message expiration interval.||Specify a message expiration interval when a device sends messages.|
|Configure subscription parameters.||Supported subscription parameters:|
|Specify a retained message|
|Specify a will message.|
|Specify the maximum length of messages on clients and servers to filter messages.|
|Specify the maximum number of QoS 1 messages per second.|
|Use the UserProperty parameter to specify a list of properties. This parameter is used to transmit additional property data. Each property consists of a key and a value.|
After a device is connected to IoT Platform over MQTT 5.0, you can view the submitted UserProperty parameter in IoT Platform logs.
Important You can add up to 20 properties. Each key cannot start with an underscore (_). The total length of a key and a value cannot exceed 128 characters.
|Add the ResponseTopic and CorrelationData parameters to enable bidirectional communication in a mode that is similar to HTTP-based request/response.|
For example, the requester is a device, and the responder is your business server. After you use the Advanced Message Queuing Protocol (AMQP) subscription or data forwarding feature, you can parse the ResponseTopic and CorrelationData parameters from the property data in the message. Then, you can call the Pub operation to send a response to the device.
|Add more response codes that can be used by devices to identify request statuses and issues.|
For more information, see Troubleshooting.
|Scale down message communication topics to integers to reduce the size of MQTT messages. This saves bandwidth resources.||N/A|
|Use shared subscription.|
A shared subscription topic is in the following format:
- Transport Layer Security (TLS)-based TCP connection: high security. Important
- TLS 1.0, 1.1, 1.2, and 1.3 are supported. We recommend that you use TLS 1.2 or 1.3 for encryption. TLS 1.0 and 1.1 are earlier versions and may cause security risks.
- Link SDK is configured with TLS 1.2 and TSL 1.3. If you use Link SDK, you do not need to configure the TLS protocol.
- IoT Internet Device ID-based TCP connection (IoT Internet Device ID is a chip-level encryption service): high security.
- Unencrypted TCP connection: low security. The feature will be phased out soon. We recommend that you do not use the feature.
For more information about the definitions and types of topics, see Topics.
You can view system topics on the Device Details page of the IoT Platform console. For information about feature-specific topics, see the documentation about specific features.
After you register a device, you can use only one protocol to connect the device to IoT Platform. You cannot use multiple protocols for the same device.
IoT Platform provides various device SDKs. You can use the device SDKs to connect devices to IoT Platform over MQTT. For more information about how to obtain a device SDK, see Download device SDKs.
For more information about how to enable MQTT communication between devices and IoT Platform by using various communication protocols, see the following topics: