MQTT is an ISO-certified protocol and is in use very widely. The interesting thing about this protocol is that it was developed by Andy Stanford and Arlen Nipper in 1999 for monitoring of an oil pipeline through the desert. As you can imagine, in middle of a desert, the protocol they developed had to be energy efficient and bandwidth efficient as well.
How this protocol works is quite interesting. It has a publish-subscribe architecture. This means, it has a central server, which we also call a broker. Any device can register with this broker and publish any meaningful data onto it. Now, the data that is being published should have a topic, for example, air temperature.
These topics are particularly important. Why, you may ask? To the broker, there can be one or many devices that can be connected. With the connection, they also need to subscribe to a topic. Let's say they are subscribed to the topic Air-Temperature. Now, whenever any new data comes, it gets published to the subscribed devices.
One important thing to know is that there need not be any request to gain the data from the broker like what we have in HTTP. Rather, whenever the data is received, it will be pushed to the device which is subscribed to that topic. It is very obvious that the TCP protocol will also be up and working during the whole time and the port related to the broker will always be connected for seamless data transmission. However, should there be any break in the data, the broker will buffer all the data and send it to the subscriber whenever the connection is resumed.
As you can see The motion sensor and the temperature sensors are giving the data to MQTT server by a specific topic namely Temperature and Motion. Those whose are subscribed to these topics would get the reading from this device. Hence there is no direct communication needed between the actual sensor and the mobile device.
The good thing about this whole architecture is that there can be limitless devices attached with this protocol and there need not be any scalability issues. Also, the protocol is relatively simple and easy to work with even a huge amount of data. Hence, this becomes the preferred protocol for IoT as it provides an easy, scalable, and seamless link between the data producer and the data receivers.