MQTT, the most important protocol of the Internet of Things, basically all the cloud platforms for charging are based on the MQTT protocol, such as wit cloud, and all open cloud platforms such as China Mobile's oneNet and Baidu's cloud platform also support MQTT access. . Although MQTT is very hot, there are currently very few MQTTs, especially how to port them to embedded. Most of the platform vendors' practices are in cooperation with module vendors to integrate the MQTT protocol into the WiFi module and the GPRS module, and bundle a sale to prevent users from understanding the core of the Internet of Things.
Before I went deep into the MQTT protocol, I thought it was a very complicated thing. After all, I always wanted to go deeper, but I couldn’t find much material in the vast network. At any time, I am constantly exploring the Internet of Things and getting to know the architecture of the entire Internet of Things. I know more and more about MQTT. In this article, we will take you first to understand the MQTT protocol. In the following article, let's take a look at how to transplant MQTT to STM32, and then how to build your own MQTT server.
The basic knowledge of MQTT, which everyone knows through Baidu, can be understood here, mainly to analyze the entire communication process of the MQTT protocol. But if you just read the words, it is difficult for everyone to understand. Therefore, we use the MQTT client MQTT.fx under Windows and the network capture tool Wireshark to analyze MQTT step by step.
first name | value | Flow direction | description |
CONNECT | 1 | C->S | The client requests to establish a connection with the server. |
CONNACK | 2 | S->C | The server confirms the connection establishment. |
PUBLISH | 3 | CóS | make an announcement |
PUBACK | 4 | CóS | Received a confirmation of the release message |
PUBREC | 5 | CóS | Release message received |
PUBREL | 6 | CóS | Release message release |
PUBCOMP | 7 | CóS | Post message completion |
SUBSCRIBE | 8 | C->S | Subscription request |
SUBACK | 9 | S->C | Subscription confirmation |
UNSUBSCRIBE | 10 | C->S | unsubscribe |
UNSUBACK | 11 | S->C | Unsubscribe confirmation |
PING | 12 | C->S | The client sends a PING command. |
PINGRSP | 13 | S->C | PING command reply |
DISCONNECT | 14 | C->S | Disconnect |
The above is the main communication protocol of MQTT. MQTT is based on TCP long connection. Firstly, it establishes a TCP connection with the MQTT server first, then sends a login request. To maintain a long connection, it is necessary to periodically send a heartbeat packet to maintain a connection with the service. Let's first use MQTT.fx to log in to the open source MQTT service.
Install MQTT.fx (note that MQTT.fx is developed by Java, the computer must be installed with JDK to install and open). Once opened, there is an open source MQTT service M2M Eclipse. Click on the gear (set button) next to the server's domain name m2m.eclipse.org, port number 1833 (MQTT default port number), and there is a Keep Alive Interval is the heartbeat time. Then open Wireshark, select the network interface to be captured, and then enter tcp.port==1883 and press Enter to capture only the packet of port number 1883. Click on the Connect server of MQTT.fx and you can see the data captured by Wireshark.
You can see that the Connect login request is sent locally to the server in the MQTT protocol. Then, the server responds with an ACK indicating that the login is successful. Then double-click the Connect Command packet, we can see the detailed packet data.
Inside the above-mentioned MQTT protocol package, the following is the corresponding binary data. Here we can compare the contents of the protocol with the attached data. Look here, do you think if you use TCP, and then package the following binary data to complete the MQTT login? Take out the network debugging assistant, ping m2m.eclipse.org to get the IP address, connect with port number 1883, and then send the binary data of the MQTT login protocol caught by Wireshark, you can see that the server responded with 20 02 00 00 to log in. success.
Going to the packet captured by Wireshark, you can see that the Ping Request heartbeat packet is sent to the server at a certain time, and the corresponding server will respond to the Ping Response.
Next, look at the core transmission protocols of MQTT, Subcribe and Publish. Simply put, after a client port (such as IoT hardware) Subcribe a topic, other clients (such as mobile phones) push Payload (valid data) to the server to the topic, the server will forward Payload to this book. Topic client (hardware).
This enables the client (mobile phone) to remotely send data to the client (IoT hardware) via the server (MQTT). Experiment with MQTT.fx. Click Subscribe and then type the led button next to the point and click the Subscribe button next to the led topic. Then go back to Publish, enter the led topic in the input box, the big box below is to enter the data to be pushed, input on, then press the Publish button, the data is pushed out. Go back to the Subcribe interface and you can see that the data has been pushed on the right. If this is the hardware received this command, you can control the lighting LED, we will achieve remote control LED lights.
To get a deeper understanding of the MQTT process, let’s go back to Wireshark and see the captured data.
The specific analysis is not detailed, and you can easily understand the attached documents.
Finally, let's understand the QoS (revision level), which is divided into three levels: 0, 1, and 2. In simple terms, the higher the level, the more reliable. QoS0, that is, after the push is finished, as to whether the other party has received it, what is received, whether the data is lost or not.
QoS1 means that after you receive the push, you have to return a puback to the other party, telling the other party to receive it, otherwise the other party will think that you have not received it, and will push you back after a period of time until you return a Puback to the other party.
Industrial plugs, sockets and couplers are mainly divided into four categories: plugs, sockets, connectors and appliance input sockets, which are generally collectively referred to as industrial plugs. Its main features are as follows:
1. Safe and reliable
â‘ This kind of product uses the color of the shell to indicate the rated voltage, such as: 40V-45V is purple, 110V-130V is yellow, 200V-250V is blue, 230V-415V is red, and 500V is black. It is easy to distinguish, and you can't get it wrong.
â‘¡Different specifications have different diameters, pole numbers, and grounding contact positions. Only the same specifications can be plugged in to prevent misplugging.
â‘¢There is protection against electric shock. The grounding pole insert sleeve in the socket is longer than the phase pole and neutral pole insert sleeve, so as to ensure that the grounding pole is connected before the phase pole is connected when the plug is inserted, and the grounding pole is finally separated when the plug is pulled out. It is very safe to use.
â‘£Holding devices are provided to clamp the plugs and sockets to prevent them from falling off after being inserted, which improves the reliability.
⑤High protection level. There are IP44 splash-proof type, IP67 anti-immersion type and so on. Not only the human body cannot touch the live parts, but it can also be used under different environmental conditions to ensure safety.
â‘¥An elastic band is added to the insert sleeve. Ensure close contact, good conductivity and long service life after the plug is inserted.
⑦There is a cable clamping device, which can clamp the cable sheath, so that it will not be pulled off, and it is safe to use.
2. Durable
â‘ Good mechanical properties. The product shell is made of high-quality engineering plastic, which has high strength, impact resistance and is not afraid of falling. The rubber and plastic used have anti-aging properties and can be used not only indoors but also outdoors, and are durable.
②Heat resistance and flame resistance. The shell and internal insulating parts have heat resistance, the temperature can reach (100±5)℃, and the important parts can withstand (125±5)℃; and it is flame retardant.
â‘¢More resistant to plug and use. For example, for a product with a rated current of 16A, the number of normal plug-in operation cycles is more than 5000 times.
â‘£The temperature rise test of conductive contact parts shall not exceed 50K, which is suitable for long-term use.
3. Strong versatility
The products adopt the standards of GB/T 11918~11919-2001, which are equivalent to IEC 60309-1 and 2 standards, and are fully in line with international standards. Therefore, such products can be used both domestically and internationally. At the same time, it has a wide variety of specifications, which can meet various occasions and uses.
These characteristics of industrial plugs and sockets give it high safety, reliability and international versatility. Therefore, it has gradually received attention in the country. Through continuous promotion and application, industrial plugs and sockets have gradually entered various industries, such as electricity, ports, machinery industries and large-scale buildings. With the development of science and technology, industrial plugs and sockets are constantly innovating. Various quick installation technologies have been gradually applied to plugs and sockets, making it more convenient to use.
IP44 Plug,IP67 Plug,IP67 Socket,IP44 Socket
Ningbo Bond Industrial Electric Co., Ltd. , https://www.bondelectro.com