A few days ago I wrote about the MQTT protocol to achieve push data transmission, so I will update my knowledge about MQTT irregularly.

MQTT: Message Queuing Telemetry Transport (MQTT) is an instant messaging protocol developed by IBM, which has the potential to become an important part of the Internet of Things. The protocol supports all platforms, connects virtually all connected objects to the outside world, and is used as a communication protocol for sensors and actuators (such as connecting houses via Twitter).

MQTT characteristics

MQTT protocol is designed for the communication of a large number of remote sensors and control devices with limited computing power and working on low bandwidth and unreliable networks. It has the following main characteristics:

1. Use publish/subscribe message pattern to provide one-to-many message publishing and release application coupling;

2. Message transmission that shields payload content;

3. Use TCP/IP to provide network connections.

4. There are three qualities of message publishing service:

"At most once", message publishing is entirely dependent on the underlying TCP/IP network. Message loss or duplication occurs. This level can be used for environmental sensor data where the loss of a read record does not matter because a second send will follow shortly after. "At least once" ensures that messages arrive, but message duplication may occur. "Only once" ensures that the message arrives once. This level can be used in cases where duplicate or missing messages result in incorrect results in a billing system.Copy the code

5. Small transmission with low overhead (the fixed length header is 2 bytes) and minimal protocol exchange to reduce network traffic;

6. Mechanisms for notifying parties of client outages using the Last Will and Testament features; MQTT feature principle

Implementing MQTT requires: client side and server side

MQTT protocols have three identities: Pushlish, Broker, and Subscribe.

MQTT messages are divided into topics and payloads

Topic refers to the type of message. After a subscriber subscribes, he or she receives a message payload for that Topic.

Payload refers to the content of a message that the subscriber uses

## Message type:

CONNECT: the client connects to the MQTT broker. CONNACK: the connection is confirmed. PUBLISH: the newly published message. PUBACK: the newly published message is confirmed. PUBREL: the second part of the QoS 2 message flow, which indicates that the message has been published. PUBCOMP: the third part of the QoS 2 message flow, which indicates that the message has been published. SUBSCRIBE: The client subscribes to a topic SUBACK: UNSUBSCRIBE: indicates that the client terminates the SUBSCRIBE message. UNSUBACK: indicates that the client terminates the SUBSCRIBE message. PINGREQ: indicates the heartbeat. The client gracefully notifies the MQTT agent before terminating the connectionCopy the code

MQTT application

Through MQTT protocol, dozens of MQTT server programs have been extended, which can send relevant messages to MQTT through PHP, JAVA, Python, C, C# and other system languages.

In addition, MQTT is widely used by many domestic enterprises as the protocol for Android mobile phone client and server to push messages. MQTT is used as message push message in Sohu and Cmstop mobile clients. Push according to Cmstop is mainly responsible for senior r&d engineers wen-kai lee said, with the development of mobile Internet, MQTT due to open source, low power consumption, etc, will be more contribution in the field of mobile news push, in the field of Internet of things, sensor and the server communication, information collection, one of MQTT are considered as a solution. MQTT will enter every aspect of our lives in the future.


Baidu Cloud access LOt-MQTT test

A configuration.

1. Register a Baidu Cloud account and open the Object Access interface:

3. Click the name of the instance you created and create the device:

Note that Topic and generated keys must be kept in mind. If the key is lost, you have to reset the key.

That’s the basic configuration.

Two. Connection test

1. Click the link to test:

2. Fill in the generated key and user name, then click Connect

3. After the connection, start the test. Fill in the theme you just set, for example, I set the theme is qzsService, the steps are as follows:

Welcome to follow my wechat official account: