tencent cloud

All product documents
IoT Hub
MQTT-Based Device Connection over WebSocket
Last updated: 2024-12-27 15:44:26
MQTT-Based Device Connection over WebSocket
Last updated: 2024-12-27 15:44:26

MQTT-WebSocket Overview

The IoT Hub platform supports MQTT communication based on WebSocket, so that devices can use the MQTT protocol for message transfer on the basis of the WebSocket protocol. In this way, browser-based applications can implement data communication with the platform and devices connected to the platform. In addition, WebSocket uses ports 443/80, which means that messages can pass through most firewalls during transfer.

MQTT-WebSocket Connection

As both the MQTT-WebSocket and MQTT-TCP protocols ultimately transfer messages based on MQTT, they have the same parameters for MQTT connection. The main difference lies in the protocol and port of the MQTT connection to the platform. Key-authenticated devices use WS for connection, while certificate-authenticated devices use WSS, i.e., WS+TLS.

Guide to connecting certificate-authenticated device

1. Download files such as the certificate and device private key.
2. Connect to the domain name. For devices in the Guangzhou region, connect to ${ProductId}.ap-guangzhou.iothub.tencentdevices.com:443, where ${ProductId} is the product ID.
3. Set the MQTT connection parameters: The connection parameter settings are the same as those for MQTT-TCP connection. For more information, please see the MQTT connection section in MQTT-Based Device Connection over TCP.
UserName:${productid}${devicename};${sdkappid};${connid};${expiry}
PassWord: password (you can set any value)
ClientId:${ProductId}${DeviceName}
KeepAlive: time to keep the connection alive. Value range: 0–900s

Guide to connecting key-authenticated device

1. Get the device key.
2. Connect to the domain name. For devices in the Guangzhou region, connect to ${ProductId}.ap-guangzhou.iothub.tencentdevices.com:80, where ${ProductId} is the product ID.
3. Set the MQTT connection parameters: The connection parameter settings are the same as those for MQTT-TCP connection. For more information, please see the "Guide to connecting key-authenticated device" section in MQTT-Based Device Connection over TCP.
UserName:${productid}${devicename};${sdkappid};${connid};${expiry}
PassWord:${token};hmac signature algorithm
ClientId:${ProductId}${DeviceName}
KeepAlive: time to keep the connection alive. Value range: 0–900s
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon