当前位置:网站首页>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
边栏推荐
- On N handshakes and M waves of TCP
- Audio knowledge (I)
- H265/webvr video web page without plug-in player easyplayer Solution to the problem of cumulative delay of FLV video played by JS
- test
- FPGA systematic learning notes serialization_ Day8 [design of 4-bit multiplier and 4-bit divider]
- Learn typescript with VAM (phase 1)
- 区块哈希游戏竞猜系统开发(成熟代码)
- How much does the page length affect the ranking?
- 05. Tencent cloud IOT device side learning -- mqtt protocol client implementation
- The problem is as big as the middle stage
猜你喜欢

Why do you develop middleware when you are young? "You can choose your own way"
![[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)

MySQL learning -- table structure of SQL test questions
Using consistent hash algorithm in Presto to enhance the data cache locality of dynamic clusters

Daily algorithm & interview questions, 28 days of special training in large factories - the 15th day (string)
随机推荐
Common GCC__ attribute__
[2021 taac & Ti-One] frequently asked questions related to the notebook function
zblog系统如何根据用户ID获取用户相关信息的教程
How much does the page length affect the ranking?
How important is it to document the project? I was chosen by the top 100 up leaders and stood up again
[MySQL practice] binlog, a sharp tool for problem analysis
[version upgrade] Tencent cloud firewall version 2.1.0 was officially released!
Several cloud products of Tencent cloud have passed IPv6 enabled cloud logo certification
Redis source code analysis RDB
Introduction to visual studio shortcut keys and advanced gameplay
Robot toolbox matlab robotics toolbox
Using consistent hash algorithm in Presto to enhance the data cache locality of dynamic clusters
Markdown syntax -- Formula
H265 video streaming web page without plug-in player easywasmlayer Troubleshooting and solution of JS unable to set cover photo
Several schemes of traffic exposure in kubernetes cluster
跟着Vam一起学习Typescript(第一期)
After the collective breakthrough, where is the next step of China's public cloud?
网站SEO排名越做越差是什么原因造成的?
Cloud development environment to create a five-star development experience
Easycvr, an urban intelligent video monitoring image analysis platform, plays national standard equipment videos and captures unstable packets for troubleshooting