当前位置:网站首页>03. Tencent cloud IOT device side learning -- overview of mqtt control package
03. Tencent cloud IOT device side learning -- overview of mqtt control package
2022-06-24 17:23:00 【fancyxu】
The main purpose of this series is to record the learning notes of Tencent cloud Internet of things device , And on the device side SDK Make a supplementary explanation .
Overview of control package format
MQTT All control packages are controlled by 3 Part of it is made up of : Fixed head + Variable head + Message body . The fixed head is divided into Package type 、 Sign and remaining length .
CONNECT | CONNACK | PUBLISH | PUBACK | SUBSCRIBE | SUBACK | UNSUBSCRIBE | UNSUBACK | PINGREQ | PINGRESP | DISCONNECT | ||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
Fixed head | Package type 4bits | 0001 | 0010 | 0011 | 0100 | 0100 | 1001 | 1010 | 1011 | 1100 | 1101 | 1110 |
sign 4bits | Retain 0000 | Retain 0000 | DUP 1bit QoS 2bits RETAIN 1bit | Retain 0000 | Retain 0010 | Retain 0000 | Retain 0010 | Retain 0000 | Retain 0000 | Retain 0000 | Retain 0000 | |
Residual length 1-4 bytes | Indefinite | 0x02 | Indefinite | 0x02 | Indefinite | Indefinite | Indefinite | 0x02 | 0x00 | 0x00 | 0x00 | |
Variable head | The name of the agreement 6bytes Agreement level 1 byte Connection sign 1 byte Time to live 2 bytes | Connection confirmation mark 1 byte Connection return value 1 byte | The theme ( length + topic name ) ( Support 1 individual ) package ID 2bytes ( only QoS1) | package ID Same as PUBLISH | package ID 2bytes | package ID Same as SUBSCRIBE | package ID 2bytes | package ID Same as UNSUBSCRIBE | nothing | nothing | nothing | |
Message body | ClientIdusr name ( Optional )password ( Optional ) | nothing | Application messages | nothing | The theme ( length + topic name ) ( Support 1 individual ) Expect the most QoS 1 byte | Return value 1 byte | The theme ( length + topic name )( Support 1 individual ) | nothing | nothing | nothing | nothing | |
Control package functions
- CONNECT: The client initiates a connection to the platform , The first packet sent per connection
- CONNACK:CONNECT Reply to
- PUBLISH: The client publishes messages to the server , The server publishes messages to the client
- PUBACK:QoS1 Used as PUBLISH reply ,QoS0 No such reply
- SUBSCRIBE: Subscribe to topics , In a conversation , The client receives the corresponding topic The published message must be subscribed first
- SUBACK:SUBSCRIBE Reply to
- UNSUBSCRIBE: Unsubscribe from a topic
- UNSUBACK:UNSUBSCRIBE Reply to
- PINGREQ: To keep alive
- PINGRESP:PINGREQ Reply to
- DISCONNECT: Client disconnected , However, the reason for disconnecting through the client is that the network is disconnected , At this time, in fact DISCONNECT The packet cannot be sent out
Control packet capture analysis
have access to SDK adopt TCP Not TLS Way to connect to the platform 1883 port , Run the example , Carry out grab bag analysis .
A brief analysis ,CONNECT The package structure is the same as above
- The head is basically fixed , The only one that can be set is Connect Flags Medium Clean Session, And the use of TLS Authentication may not be required User Name and Password
- Not TLS Under authentication , Connecting platform 1883 port , Authentication passed User Name and Password.
Mainly aimed at CONNECT Reply of package , No other special , Mainly the return value Retrun Code There will be differences on
SUBSCRIBE and SUBACK Is the corresponding relation , among Message Identifier To match ,QoS Settings should also correspond to .
QoS0 Of PUBLISH The package didn't reply
PUBLISH and PUBACK Is the corresponding relation , among Message Identifier To match ,QoS Settings should also correspond to .
When you disconnect , Sent by client , Usually not , Because in general MQTT It's all about maintaining a long connection , And the connection is often disconnected because of the network , This is the time DISCONNECT Packets generally cannot be sent out
边栏推荐
- See through the new financial report of Tencent music, online music needs b+c
- Snapshot management for elastic cloud enterprise
- 构建跨公链平台解决DApp开发问题
- Pagoda activities, team members can enjoy a lightweight server 1 core 2g5m 28 yuan for two years
- Elastic searchable snapshot function (frozen Tier 3)
- A solution for building live video based on open source real-time audio and video webrtc architecture
- Example description and case of ansible playbook automated cluster server management
- Industrial security experts talk about DDoS countermeasures from the perspective of attack and defense
- MySQL learning -- table structure of SQL test questions
- What securities dealers recommend? Is it safe to open an account online now?
猜你喜欢

Why do you develop middleware when you are young? "You can choose your own way"

MySQL learning -- table structure of SQL test questions

Daily algorithm & interview questions, 28 days of special training in large factories - the 15th day (string)
Using consistent hash algorithm in Presto to enhance the data cache locality of dynamic clusters
![[leetcode108] convert an ordered array into a binary search tree (medium order traversal)](/img/e1/0fac59a531040d74fd7531e2840eb5.jpg)
[leetcode108] convert an ordered array into a binary search tree (medium order traversal)
随机推荐
Markdown syntax -- Formula
[version upgrade] Tencent cloud firewall version 2.1.0 was officially released!
Daily algorithm & interview questions, 28 days of special training in large factories - the 15th day (string)
Radiology: contralateral preoperative resting state MRI functional network integration is related to the surgical results of temporal lobe epilepsy
Tencent cloud database mysql:sql flow restriction
C language | logical operators
CentOS 7 installing SQL server2017 (Linux)
About with admin option and with grant option
March 27, 2021: give you a head node of the linked list, and rotate the linked list
How to convert XML to HL7
C4D learning notes
[leetcode108] convert an ordered array into a binary search tree (medium order traversal)
Create a green city and 3D visualization of digital twin natural gas stations
Implement typescript runtime type checking
Try catch finally implementation mechanism
网站SEO排名越做越差是什么原因造成的?
[MySQL practice] binlog, a sharp tool for problem analysis
2021-04-02: given a square or rectangular matrix, zigzag printing can be realized.
Analysis of software supply chain attack package preemption low cost phishing
One article combs multi task learning (mmoe/ple/dupn/essm, etc.)