In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what is the use of MQTT protocol". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what's the use of the MQTT protocol"?
MQTT (Message Queuing Telemetry Transport), which means message queuing telemetry transmission. In the early years, when the PC side was popular, many engineers had never heard of the term detour at all, but with the gradual development of the Internet of things (IoT) technology, this protocol appeared more and more frequently in front of the major engineers. As a result, many engineers only know its name, and even many hot people think that this is a protocol developed with the development of IoT. In fact, the MQTT agreement was first invented more than 20 years ago, and in 1999 Andy Stanford-Clark of IBM and Alan Nip of Cirrus Link wrote the first version of the agreement. Later, this protocol was also standardized internationally and became a message protocol based on the publish / subscribe paradigm under the ISO standard (ISO/IEC PRF 20922). IBM submitted the MQTT version 3.1 specification to the Organization for the Promotion of structured Information Standards in 2013, with a charter to ensure that only minor changes can be made to the specification, and the MQTT protocol has been used in some niche areas ever since. After the completion of the Internet of things technology infrastructure, this ancient protocol began to radiate its first spring.
The transport layer and application layer of Ethernet are well known that the rapid development of the Internet of things is inseparable from the infrastructure of the communication network. You can now control the light switch of a room in your home anywhere in the world. Or when you do industrial control, you can also remotely control the movement of a robot. The maturity of this technology is based on network communication. At present, the main technology of network technology is the OSI seven-layer model, of course, the practical application actually uses the TCP/IP four-layer network model.
The third layer of the TCP/IP four-layer network model is the famous TCP/IP protocol. The main purpose of this layer protocol is to transmit communication data sent by one computer on the network to another machine with a specified IP address. For example, a machine with IP address "192.168.137.19" sends 16-byte binary packets to machines with IP address "192.168.137.10". Then it can be transmitted using TCP/IP protocol. Instead, when using TCP to transmit data, our common way is to use socket.
But when the machine with the IP address of "192.168.137.19" sends data to the machine of "192.168.137.10", what exactly does the data in this packet of TCP packet mean, and how the machine with the IP address of "192.168.137.10" at the receiving end parses the data of this packet? this problem is solved by the protocol of the upper layer of the transport layer, which is the application layer protocol. Of course, if your protocol does not want to be parsed by ordinary computers on the network, you can also make some application layer protocols yourself. it doesn't matter, the purpose of the transport layer is to transmit the data to the target machine. We often encounter a variety of application layer protocols in our daily work and entertainment. For example, when you open a web page, the picture is displayed in that location, and what function is achieved when this button is clicked? this is agreed by the HTML Hypertext transfer Protocol (English: Hyper Text Transfer Protocol, abbreviation: HTTP). This ensures that a page in your site can be displayed properly when it is requested by any device. In addition to HTTP, there are many application layer protocols, such as DNS,FTP, and our protagonist MQTT protocol is also one of them.
Why does the Internet of things tend to MQTT since there are so many excellent application layer protocols in our existing applications, why does MQTT shine brilliantly in the field of the Internet of things? In fact, the choice of MQTT protocol is not groundless. MQTT is a lightweight and flexible network protocol dedicated to achieving the right balance for IoT developers: this lightweight protocol can be implemented on severely constrained device hardware and high latency / bandwidth limited networks. Its flexibility makes it possible to support a variety of application scenarios for IoT devices and services. Most developers are already familiar with HTTP Web services. So why not let the IoT device connect to the Web service? The device can send its data in the form of HTTP request and receive updates from the system in the form of HTTP response. This request and response pattern has some serious limitations: HTTP is a synchronization protocol. The client needs to wait for the server to respond. Web browsers have this requirement, but at the expense of scalability. In the field of IoT, a large number of devices and possibly unreliable or high-latency networks make synchronous communication a problem. Asynchronous messaging protocols are more suitable for IoT applications. The sensor sends the reading, allowing the network to determine the best route and time to send it to the target device and service. The HTTP is unidirectional. The client must initiate a connection. In IoT applications, devices or sensors are usually clients, which means that they cannot passively receive commands from the network. HTTP is an one-to-one protocol. The client makes a request and the server responds. Delivering messages to all devices on the network is difficult and costly, which is a common use case in IoT applications. HTTP is a heavyweight protocol with many headers and rules. It is not suitable for restricted networks. For these reasons, most high-performance, scalable systems use an asynchronous message bus for internal data exchange instead of Web services.
What is interesting about the subscription / publish model is that the MQTT server is actually much simpler than the web server design, because it pursues an efficient service. The main mechanism of MQTT for sending and receiving messages is similar to the relationship between our official account and our readers. In the real world, like everyone else, I am similar to having a MQTT device attached to a unified server, and people subscribe to us out of interest in our official account or some kind of affection, and when I tweet every day, my push message will appear in everyone's mobile phone. In this process, the way you get my information is called "subscription". And my act of releasing news to this official account is "publishing". When you see my article, you can leave a message to me at will, this behavior is everyone's "publish" behavior, and I always stay in front of a certain push to read your messages, this is a kind of "subscription" behavior. In this process, all the external information has nothing to do with us, we simply communicate with the information flow in both directions. The messaging mechanism in MQTT is also based on the "Publish"-"Subscribe" model.
The specific operation steps of MQTT are as follows: the first step: get a MQTT server first, and then create a new MQTT communication product. Step 2: then connect to the server. The two important parameters to connect to the server are the host number (domain name or IP address) and port number. Step 3: if you are using a third-party CVM platform, it may require you to log in to the device using product ID and authentication information, both of which can be found in the backend of the device cloud. After completing the three steps, you can subscribe to or post messages to the corresponding topic. Later, I will organize a special document to show you how to "whore" a China Mobile device cloud open access platform. These three steps are suitable not only for application software development, but also for single-chip microcomputer development. In the development of single-chip microcomputer, if you use AT instructions to communicate with external WIFI modules, then general modules can have their own AT+MQTT commands, which is the best way to greatly reduce the pressure on single-chip computers. Or you can directly obtain the data of the TCP/IP transport layer, and then parse the MQTT yourself, which requires users to have a deep understanding of the MQTT protocol and to parse the Json data themselves, so generally, when doing embedded devices, it is recommended that you directly use the module with MQTT protocol, and it is more convenient to parse the AT instructions directly.
Case study: remote control of lights and access to the current room temperature. In this case, it is actually the simplest application of MQTT. First of all, the embedded control board of the room is mainly connected to the server through WIFI, which can not only control the light switch, but also collect temperature. The terminal device far away is a mobile phone. To keep communication normal, they first need to access the same MQTT server. The temperature information on the device side is collected by the device, so it is necessary to publish the collected data to the "temperature" topic, and the mobile phone acquires this temperature information, so you need to subscribe to this "temperature" topic. Once the device sends temperature information to the "temperature topic", the topic will be received by the mobile phone. The light control on the device side is performed by the device, so you need to subscribe to the "light switch" topic, and the mobile phone controls the light switch, so you need to publish control information for this "light switch" topic. Once the mobile phone sends the light on message to the "light on" topic, the topic will be received by the terminal and then execute the light on command. At this point, I believe you have a deeper understanding of "what is the use of the MQTT protocol?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.