Use the network debugging assistant to send a CONNECT message to connect to Alibaba Cloud
Reference: https://blog.csdn.net/daniaoxp/article/details/103039296
In the previous article, I introduced how to assemble the CONNECT message and how to calculate the remaining length
CONNECT message: https://blog.csdn.net/weixin_46251230/article/details/129392102
Calculate the remaining length: https://blog.csdn.net/weixin_46251230/article/details/129394172
In this experiment, the network debugging assistant sends a CONNECT message to connect to the Alibaba Cloud platform
1. Create an Alibaba Cloud device and obtain MQTT connection parameters
Create Aliyun device: https://blog.csdn.net/weixin_46251230/article/details/128993864
2. Convert MQTT connection parameters
Convert clientId, username, and passwd to hexadecimal, and you can use the network debugging assistant to convert
Select UDP as the protocol, select the address of your own host, port 8888, and select your own host address on the remote host, select ASCII mode, paste the parameters in this mode, first paste the clientId, and remove the extra spaces
Then click HEX, the ASCII code in the input box will be automatically converted to hexadecimal, copy these hexadecimals to the text document
Click Reset Count in the lower right corner, then click Send, you can see that 80 characters have been sent
Convert 80 to hexadecimal 0x50 and put it in front of the hexadecimal data of the text document. It must conform to UTF-8 encoding, so add 00 in front
Similarly, convert both username and passwd to hexadecimal format
3. Assemble the CONNETC message
The payload is to combine the hexadecimal data of clientId, username, and passwd
Fixed header + variable header, the remaining length can be replaced with ??, and left blank
Combine data in order of fixed header + variable header + payload
4. Calculate the remaining length
Copy all the characters after ?? to the network debugging assistant, reset the count, click send, and you can see that a total of 180 bytes have been sent
According to the steps of calculating the remaining length, 180 is greater than 128 and less than 16383, so two bytes are used to represent
According to the formula 180=128*a+b, it can be calculated that a = 1, b = 52, a is in the upper 8 bits, b is in the lower 8 bits, the lower bits come first, and the higher bits follow, so the writing order is ba
b = 0011 0100 = 1011 0100 (the highest bit indicates that there are bytes after the remaining length, so it must be actively set to 1)
b = B4
a = 0000 0001 = 01
Paste B4 01 into combined data
5. Connect to Alibaba Cloud platform
Aliyun server address (East China 2): *.iot-as-mqtt.cn-shanghai.aliyuncs.com
*Replace with the ProductKey of your own device
Such as: i6deo513xT1.iot-as-mqtt.cn-shanghai.aliyuncs.com
The port number is 1883
Change the network debugging assistant to TCP Client, fill in the remote host address as i6deo513xT1.iot-as-mqtt.cn-shanghai.aliyuncs.com, port number 1883, click HEX, copy and paste the above combined CONNECT message into the input box , click Connect, then click Send
When receiving, remember to set it as HEX reception. If the last byte in the information returned by Alibaba Cloud is 00, it means that the connection is successful. If it is not 00, the connection fails. The subscript is the possible value of the last byte, only 0x00 Yes means the connection is accepted
At this point, you can see that the devices on the Alibaba Cloud platform have been displayed online