Haixin Zhisheng: The MQTT Protocol of the Internet of Things

What is the MQTT protocol

  MQTT (Message Queuing Telemetry Transmission Protocol) is a lightweight bidirectional message transmission protocol developed by IBM in 1999 specifically for application scenarios such as the Internet of Things. It is mainly to solve the problem of mutual communication between devices used in the Internet of Things, and The problem of communication between these devices and the back-end application system.

Why do you need an MQTT (or similar) protocol

  With the rapid development of intelligent hardware and mobile Internet technology, traditional Internet protocols are becoming more and more difficult to meet the needs of the Internet of Things, which are reflected in: mobile networks are expensive, low bandwidth, and poor reliability; running in embedded devices, processors and memory Limited resources; massive online devices generate huge data, which brings a lot of network overhead and processing pressure to the cloud.

How MQTT works

  MQTT includes a client and a broker. Taking a smart home system as an example, the terminal smart appliances and mobile phones are the clients, and the cloud center is the broker. The client first initiates a request to the agent, and the agent authenticates the client after receiving it. After the authentication is passed, a TCP long connection channel is established between the client and the agent. The client subscribes to several topics of interest through this channel, and at the same time When its own state changes, it publishes a message to the corresponding topic, and the agent sends the message to all clients that are subscribing to the topic, as shown in the following figure. Unlike HTTP, MQTT is a many-to-many communication protocol. Devices are not directly connected, but communicate with each other through a proxy. It is a natural asynchronous protocol, which can well decouple the requester and the responder.

What are the benefits of the MQTT protocol

  MQTT is optimized for IoT scenarios, considering network accessibility, message connectivity, and energy consumption. Specifically:

  One is that it is very lightweight, using an 8-bit system and 30K space to run the MQTT client.

  The second is that it is designed for unstable networks. In general, transmission protocols are based on stable network transmission, and some optimizations will be made specifically for this stable network. MQTT is just the opposite. The protocol considers the uncertainty of the network more, and it is also very streamlined. The minimum transmission byte is only two, so that it still has a good message reachability rate under poor network conditions.

  Third, the interaction mode of its messages is not the same as in the traditional sense. It adopts the mode of publishing and subscribing. When a data source publishes a message, multiple subscribers can receive the message at the same time, which is more flexible for IoT scenarios where many devices are interconnected.

  Fourth, there is a quality of service (QoS) mechanism for message publishing. Users can choose the transmission quality of "at most once", "at least once" or "only once" according to the needs of the application scenario, and make a trade-off between efficiency and quality.

  The fifth is the notification mechanism of abnormal interruption of the client (Last-Will-And-Testament). When a device cannot be connected, the server has a special mechanism that can immediately know what happened to the device, so that it can give feedback very quickly and make some compensation for a certain node.

What are the successful practices of MQTT

  1. IoT Cloud

  Evothings: A foreign IoT ecological platform that provides a full set of software and hardware development tools to help developers build smart hardware prototypes and develop message push services.

  Yeelink: One of the largest IoT cloud platforms in China, provides sensor cloud services for users and smart hardware developers, and realizes reliable status monitoring through real-time data processing.

  2. Real-time message push

  Facebook is an early Internet giant that adopts the MQTT protocol on a large scale. It uses MQTT in mobile clients to update notifications, messages and bookmarks.

  Cloud Bar and other platforms provide real-time message services with the help of the MQTT protocol, push messages to any device in real time, quickly send messages to millions of users, realize one-to-one push from a single device, and display online users and usage in real time. Currently, it is providing push services for tens of thousands of developers and hundreds of millions of terminals. Domestic companies such as Sohu also use MQTT as the protocol for pushing messages between Android mobile client and server.

What are the problems with MQTT

  1. It does not perform well in the 2G/3G network environment where the network changes frequently or is unstable.

  After each TCP disconnection or network disconnection, the client will immediately initiate a TCP reconnection. After the connection is successful, it will send the CONNECT command and subscribe the SUBSCRIBLE command in turn. When the network switches frequently or is not stable, the above mechanism is aggravated to a certain extent. weak network burden. Some reference resources point out that adjusting the reconnection strategy and waiting for timeout at the business level can optimize this problem. In addition, other IoT protocols based on UDP transport such as CoAP have better adaptability to such networks.

  2. For terminal environments without TCP/IP support, MQTT cannot be applied.

  可以采用MQTT-SN(MQTT For Sensor Networks)协议进行补充,它是为了非常受限类似传感器设计的,能够基于IEEE 802.15.4等无线局域网发送UDP数据包,再通过MQTT-SN网关与MQTT broker建立连接。流程架构大致如下:

MQTT推荐资源

  Mosca:基于Nodejs实现的一款功能较完善的broker

  Paho: C/C++、Python、Java等语言的MQTT 客户端库

  mosquitto:一款功能完善的开源原生broker

版权声明:原文出处:http://mt.sohu.com/20160310/n439960879.shtml?qq-pf-to=pcqq.c2c,作者:海鑫科金,感谢原作者的辛苦创作,如转载涉及版权等问题,请与我们联系(公众号:数通畅联)将在第一时间处理,谢谢!

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327098537&siteId=291194637