MQTT

MQTT(Message Queue Telemetry Transport) is an open connectivity transport standard created by IBM in 1999. The protocol generally works on top of TCP, which provides a simple, reliable stream, but can also work on top of UDP(MQQT-SN). Its goal is to collect data from many small devices in a large network, centralize and transport that data to the IT infrastructure, so that It can be monitored and controlled from the cloud.  So the goals of the MQTT protocol are essentially to extend the connectivity beyond the boundaries of an enterprise, all the way to the devices which lie at the boundaries. Essentially, MQTT enables massive scalability and deployment for many different solutions for which IOT's suitable. It's designed to service many devices with limited computational and communication capabilities, with a low bandwidth,relatively high latency, and so is designed for low bandwidth, high latency,and unreliable networks. The main goals of MQTT are thus to minimise network bandwidth, minimise device ressource and keep an assurance of delivery. To meet that requierements, MQTT keeps simple, with lightweight messages( the header is only two bytes long for MQTT) , and uses a publish/subscribe method.

   As we can see on the diagram, three types of devices are present:

* Publishers: The role of a publisher is to connect to a message broker and publish its content on the message broker. Typically, a publisher could be a sensor, for exemple. Once a message is published, it can be available to anybody who is interested in it. The Publisher must choose whether the content should be retained by the server or not.
* Broker: It is a unique feature of a MQTT architecture. The broker resides between publishers and subscribers, and it recieves all the communications. It acts as a server but this server has one dedicated purpose. It relays messages between clients.
* Subscribers: A subscriber connects to the message broker and it subscribes to content which it is interested in. Then, the message broker relayed the published content to all of those subscribers who are interested in a particular content.

The ordering of topics follows the tree structure, like directories, or like a file system. So the forward slash character is used as a delimiter when the topic path is described. When one subscribes to content, then a subscriber can subscribe either to a specific topic, by providing its path, or more generally, it can subscribe to an entire branch if it uses a wild character. For example, a sensor will publish measured temperature as a topic. So we have a highest level name, "house measurements". A subscriber can subscribe only to temperature, which is a folder in "house measurements", but can subscribe to the entire branch, if it wants to have have the data of "house measurement".

One advantage of MQTT is that, in that kind of structure, each individual Publisher and subscriber can be protected by a firewall, that only the broker can cross. A few options can be added in MQTT: Initially, when an MQTT client connects to the server, it has a choice of setting the clean session flag to true or false. If the flag is set to true, then all of the client's subscriptions are removed as soon as the client disconnects from the server. On the other hand, if the flag is set to false, then that connection is treated as durable and the subscription remains in effect even after disconnection. So subsequent messages that arrive carrying a high QoS designation are stored for later delivery after the connection is re-established. MQTT also has the concept of a will. When an MQTT client connects to the server, it can inform the server that it has a will. This is a message that should be published to a specific topic or topics in case that there is unexpected disconnection of that client to that server. A will is particularly useful in alarm or security settings where system managers must know immediately when the remote sensor has lost contact with the network. On an other hand, the MQTT broker can retain messages to be delivered to late joining applications and clients could use this to build state management at the application level.

MQTT targets applications such as monitoring an oil pipeline for leaks or vandalism, that require message feeds from thousands of sensors to be concentrated into a single location for analysis. When the system finds a problem, it can take action to correct that problem. Other applications for MQTT include power usage monitoring, lighting control and even intelligent gardening and agriculture. They share a need for collecting data from many sources and making them available to the IT infrastructure.

On a security level, the broker should be specially protected against security breaches and denial of service attacks. There is no end-to-end( client to client security). Security is provided only at the transport level between each client and the broker. It relies on transport level security to authenticate the broker and provide integrity and confidentiality of the information: Transport Level Security (TLS) for MQTT and Datagram Transport Level Security (DTLS) for MQTT-SN.

## See also

* CoAP
* HTTP
* OPC
* 6LoWPAN

## Sources

https://courses.edx.org/courses/course-v1:ColumbiaX+DS103x+2T2016/courseware/71dc0cb2d3444b9cbaeb54d35e829666/a67c18fe744c41aebc44efc6ab721dd2/

https://courses.edx.org/courses/course-v1:ColumbiaX+DS103x+2T2016/courseware/71dc0cb2d3444b9cbaeb54d35e829666/4760478519f54a80901b35eda3e6b9d8/

http://www.iiconsortium.org/pdf/IIC\_PUB\_G5\_V1.0\_PB\_20170228.pdf