MQTT(Message Queue Telemetry Transport) is a Client Server publish/subscribe messaging transport protocol. This protocol is widely used in the field of IoT for communication between Machine to Machine because of its following features ,
- light weight,
- open, and
- designed so as to be easy to implement.
Hence these features are Ideal for the IoT purpose as we need to transmit mostly status of one machine to another.It was originally developed by IBM and is now an open standard.
Note: If you are not familiar with Node MCU module, I’ll request you to watch my video Getting started with Node MCU before going into MQTT.
Working of MQTT Transport Protocol.
This protocol is easy to implement and also very easy to understand. It basically comprises of one Broker and multiple clients where clients can be treated as our smart phone, sensors, etc. and they all communicate with the server which is known as Broker.
In this protocol, every client need to connect to any address of the broker which is known as the topic to be subscribed in MQTT. In single broker there can be multiple topics and clients can also subscribe to multiple topics of the same broker.
First lets see this process in block diagram which will be easy for you to understand.
So basically here we have one broker and 3 clients subscribed to the topic “temperature”.
So as soon as any of the client(Temperature Sensor) publishes or updates the value of Temperature to the broker, than all the clients(Smart Phone) subscribed to that topic will receive the value of temperature updated.
We can do a lot with this simple protocol. We can even subscribe to the topics of any other person if we know the username and password of the broker.
We will be making a project on “Controlling Home Appliances through Internet via MQTT”. I will be demonstrating this by controlling Radio and Light of my room.
Things required for making this:
- ESP8266 12e development Board
- 6V Relay x2
- BC547 Transistor x2
- 330 ohm Resistor x2
- Connecting wires
First of all we will need a MQTT broker. There are many broker for MQTT but I have used Adafruit MQTT broker. Its quite simple and its UI is also great. You will love to use that broker. For using Adafruit MQTT broker, first of all you need to make an account on Adafruit.io. Fill up the basic details and you are ready to use that broker.
Than goto your dashboard. My dashboard is like this.
There many options on the right corner of the page to edit the blocks, add new blocks,get the key,etc.
Now we will start with making a new button on the dashboard. For that click on the 2nd button i.e.”Create a New block”. It will show this window.
There are number of blocks to be added in this window like toggle button, push button, slider etc. In our project we will be using the first block i.e. toggle button. Click on create button and you will get following options.
Than you have to provide feed name which should be unique because this feed name is nothing but the topic which clients will be subscribing. I have given name of the feed as onoff. Than click the create button. And click on the choose button front of your feed name. Than click on the next step.
- Broker URL, here it is (io.adafruit.com)
- Port, (1883)
- Username ( username you have registered while making your account)
- Password (Key which you can get by clicking the key icon on your dashboard)
explore | learn | share