tencent cloud

IoT Hub

Release Notes and Announcements
Release Notes
Product Introduction
Overview
Features
Strengths
Use Cases
Use Limits
Basic Concepts
Getting Started
Quick Start
Scenario 1: Device Interconnection
Scenario 2: Device Status Reporting and Setting
MQTT.fx Connection Guide
Console Guide
Product Management
Rule Engine
Sub-account Access to IoT Hub
Firmware Upgrade
Resource Management
Certificate Management
Developer Manual
Feature Components
Signature Algorithm
Device Authentication
Device Connection Protocol
Gateway Subdevice
Message Communication
Device Shadow
Device Firmware Upgrade
Remote Device Configuration
Resource Management
Device Log Reporting
NTP Service
Device Connection Manual
Device Connection Overview
Connection Based on SDK for C
Connection Based on SDK for Android
Connection Based on SDK for Java
Connection Based on SDK for Python
API Documentation
History
Introduction
API Category
Making API Requests
Device Shadow APIs
Device APIs
CA Certificate APIs
Product APIs
Data Types
Error Codes
FAQs
General
Device Connection and Reporting
Rule Engine
Console
IoT Hub Policy
Privacy Policy
Data Privacy And Security Agreement
Glossary

MQTT-Based Device Connection over WebSocket

PDF
Focus Mode
Font Size
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

Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback