What is MQTT & What's the benefit in using MQTT instead of HTTP ? - Black keyhole

welcome to our keyhole, we provide you various knowledge from various sources such as Electric&Electronic, Health, Arduino, IOT, Diy projects, A/l past paper and model paper, Even though you can keep in touch with current technology

What is MQTT & What's the benefit in using MQTT instead of HTTP ?

Share This


What is MQTT?

MQTT stands for MQ Telemetry Transport. It is a publish/subscribe, extremely simple and lightweight messaging protocol, designed for constrained devices and low-bandwidth, high-latency or unreliable networks. The design principles are to minimise network bandwidth and device resource requirements whilst also attempting to ensure reliability and some degree of assurance of delivery. These principles also turn out to make the protocol ideal of the emerging “machine-to-machine” (M2M) or “Internet of Things” world of connected devices, and for mobile applications where bandwidth and battery power are at a premium.

It provides resource-constrained network clients with a simple way to transmit their telemetry information. It is designed for connections with remote locations where small messages are required or the network bandwidth is limited. MQTT being event driven protocol brings the transmission costs down.

The publish-subscribe messaging pattern requires a message broker. It consists of clients communicating with a server(Broker). A client may be either a publisher or a subscriber. Each client can connect to the broker. The message exchange is done on the basis of Topic, which is a kind of hierarchy .

The MQTT protocol provides username and password fields in the CONNECT message for authentication. The client has the option to send a username and password when it connects to an MQTT broker.The username is an UTF-8 encoded string. The password is binary data with a maximum of 65535 bytes.

There are several famous messaging platforms/applications that implement MQTT viz. Facebook Messenger , Amazon IoT, Microsoft Azure IoT, Node-RED, McAfee, etc.

Another important concept are the topics. Topics are the way you register interest for incoming messages or how you specify where you want to publish the message.

Topics are represented with strings separated by a forward slash. Each forward slash indicates a topic level.

  Eg: School/office/bulb

Topics are case sensitive which makes these two topics different

     Eg: School/office/bulb  !=  scHool/Office/Bulb

Subscribe to watch my video version of tutorial here

What's the benefit in using MQTT instead of HTTP ?

HTTP is (or was) primarily a request-response protocol built on top of TCP. i.e. a client (web browser) sends a request (open a TCP connection and send a specifically formatted text message) to a server ( a web server). The server then sends back an appropriate response and the connection is closed.

HTTP 1.1/2 introduce persistent connections, binary framing mechanisms, websockets etc. More information on the request / response mechanism 

MQTT is a publish-subscribe protocol based on TCP. A client connects to a server. The client can then subscribe to various topics. The client and the server can then publish messages to various topics and the server is responsible for delivering it to various interested clients.

As with all things networking, you should choose the one that best fits into your overall ecosystem. If you are doing IOT things (lots of sensors sending a large aggregate of data), then MQTT (or AMQP) makes sense because all of the major cloud OT vendors support it directly and pretty much all IOT devices that have internet connectivity also support it. There are plenty of apps, too, which you can use to debug your MQTT sessions.

Lastly (and this is more of an AFAICT), an MQTT server is a little more “plug and play” than an HTTP server. When you make an HTTP server, you’ll need to figure out how to extract the message that you’re sending and place it into a database that you also have to design the schema for. If you want to just “get started” with MQTT, there are public servers to test against and the major IOT cloud vendors all seem to have some kind of trial offer.

The lightweight-ness of MQTT is pretty good, but is unlikely to be your major expense.

No comments:

Post a Comment

business queries