Low Cost Home Automation With ESP8266 and Lightweight Protocol MQTT
Low Cost Home Automation With ESP8266 and Lightweight Protocol MQTT
Jignesh Patoliya2
Hitesh Patel3
2&3Faculty
Abstract: There are different types of protocol is used in IoT (Internet of Things) devices. One of the
most advance and useful protocols is MQTT (Message Queuing Telemetry Transport). Second basic
protocol is TCP that is used in this paper of different purpose. MQTT is broker based
publishing/subscribing messaging protocol. It is very easy to implement, open, lightweight, low
bandwidth protocol. This paper described about implementation of MQTT and TCP protocol in
particular ESP8266 Wi-Fi device which are very useful for IoT application such as home automation.
Index Terms: ESP8266, IoT, Home Automation, MQTT, TCP, Wi-Fi
I.
INTRODUCTION
As we know people are increasingly dependent on their smartphone. Using that smartphone they
obvious get real-time message and take a decision accordingly. Now a days this can be done using TCP/IP
protocol to send message directly to the mobile phone.
Therefore the simplest solution is to connect devices to the smartphone. Various advantages of MQTT
protocol so that this is our choice. It is very simple, open, lightweight, low bandwidth and very easy to
implement messaging protocol. This protocol is used in different types of embedded systems. IoT is stands
for Internet of Things. In a very simple manor IoT is use for controlling or nominating the device which are
so far away from us. Using different types of protocol we can done easily.
In this paper, MQTT and TCP protocols are implement in ESP8266 Wi-Fi module. With the help of this
Wi-Fi device we can control and monitoring our home devices like fan, light, AC, or this type any devices.
We can also interface different types of sensor like proximity, PIR sensor.
II. PROTOCOL OVERVIEW
There are different types of protocol which used in IoT application. According to different application
we must use different protocols. [2]
A. CoAp
The Constrained Application Protocol (CoAP) is a request / response application layer protocol. This
protocol runs over UDP. It uses the HTTP commands GET, PUT, DELETE and POST to provide client-server
architecture. CoAP has two bits in the header of each packet state the type of message and the require
Quality of Service (QoS) level.
1)
2)
3)
4)
B. XMPP
The Extensible Messaging and Presence Protocol (XMPP) was designed for message exchanging and
chatting. This protocol runs over TCP and provide request/response and also publish/subscribe messaging
systems. As above discussion XMPP support publish/subscribe architecture which are more suitable for the
IoT in compare to CoAP approach. XMPP does not support QoS level.
C. AMQP
The Advance Messaging Queuing Protocol (AMQP). It is run over TCP. This protocol provides
publish/subscribe architecture to communicate with messaging. The main advantage of AMQP protocol is
store and forward feature that ensures after network disruption. It has three QoS levels.
1) At most once: Message is sent once either if it is delivered or not.
2) At least once: Message will be delivered one time definitely but possible more then once.
3) Exactly once: Message will be delivered only one time.
D. MQTT
The Message Queue Telemetry Transport (MQTT). It runs over TCP. This is also support
publish/subscribe architecture. MQTT was released by IBM and targets lightweight M2M communication.
14
Techscripts
In this paper we use this MQTT protocol so that detail description is given. [5]MQTT protocol is containing
three QoS level.
1) Fire and forget: Message is sent once and no acknowledgement.
2) Delivered at least once: Message is sent at least once and required acknowledgement.
3) Delivered exactly once: Message is delivered exactly one time no copy of messages.
In MQTT one of the very important parts is broker that contains TOPICS. Each client can be a publisher
that send message to the broker to a specific topic and subscriber that receives automatic message every
time. A figure that demonstrate the publish/subscribe architecture. On one side is client and other side is
Server.
Description
Transmit
Receive
CH_PD
GPIO 0
GPIO 2
RST
VCC
GND
B. ESP - 12
ESP 12 is the most popular and flexible device in todays market. It exposes the most GPIO pins for
use. The Pin out of ESP- 12 is shown in below figure:
15
Techscripts
Description
Transmit
Receive
Chip enable [0- Disable, 1- Enable]
Should be HIGH on boot , LOW for flash update
Should be HIGH on boot
Also used for SPI MOSI
Also used for SPI MISO
Also used for SPI clock
Analog Pin
Regular GPIO
Regular GPIO
External Reset [0 Reset, 1 Normal]
3.3V
Ground
IV. SYSTEM IMPLEMENTATION
So here we know about MQTT protocol and also some basic information about ESP8266 module. Hence
how to implement this protocol in ESP module and which software are used in this particular paper.
A. Hardware Part
ESP8266 is a Wi-Fi device capable of running self-contained application. So we can also dumped
program in ESP device. First of all check module AT command and its response. For that configure your
device this way:
16
Techscripts
If Arduino IDE is being installed then install ESP8266 Generic Board. After that check blink example and
dumped in ESP8266 device for test.
V. SYSTEM CONFIGURATION
A very simple example of home automation is light on or off using your android phone. There are
mainly couple of modes in ESP8266 that I configure through program which are online mode and offline
mode.
A. Online Mode
Online mode works same as its name suggest. This mode is use when you are not at home and you want
to control your home device at outside the home. Then here I configure online mode in ESP8266 through
program. In this mode I choose MQTT protocol. As we know MQTT protocol uses publish/subscribe
architecture so for that we have to create different topics and that particular topic publish or subscribe data.
In programing I made different topics for controlling home automation device and that topic also configure
in android application.
So for android application go to the play store and download MyMQTT application and configure
this way:
17
Techscripts
TOPIC: reset
DATA: rst Reset all configuration
B. Offline Mode
In offline mode we can control our home device with in specific range. This range is about 100m to 300m
which is ESP module Wi-Fi range. If you want to use MQTT protocol in offline mode that is possible. But the
problem is one operating system device needs compulsory. We can use Raspberry pi or we can also use over
Laptop. Mosquitto broker is available for OS device so for that we have to install that particular broker in
Raspberry pi or Laptop.
If we choose this protocol for offline mode we have to purchase raspberry pi which is costly about $35.
So instead of MQTT protocol I used TCP protocol and therefor no need of raspberry pi or laptop. In Offline
mode my ESP8266 Wi-Fi module work as an access point so by default its IP Address is 192.168.4.1 and here
port is set by me is 8080.Now download the TCP client application which is located at Google play store.
After downloading the application configure application this way:
18
Techscripts
resolved by integrating a separate Analog IO Expander circuit with the Wi-Fi module.
REFERENCES
[1] Neil Kolban Kolbans Book on ESP8266, 2015.
[2] Tasos Kaukalias and Periklis Chatzimisios, Internet of Things (IoT) C Enabling technologies,
Application and open issues, Encyclopedia of Information Science and Technology (3rd Ed.), IGT Global
Press, 2014.
[3] Sye Loong Keojh, Sandeep s. Kumar, Hannes Tschofenig, Securing the Internet of Things: A
Standardization Perspective, Internet of Things Journal IEEE (Volume: 1, Issue: 3), June 2014, pp. 268275.
[4] Maria Rita Palattella, Nicola Accettura, Xavier Vilajosana, Thomas Watteyne, Luigi Alfredo Grieco,
Gennaro Boggia, Mischa Dohler, Standardized Protocol Stack for the Internet of Things,
Communications Surveys & Tutorials IEEE 15(3), 2013, pp. 1389-1406.
[5] http://www.hivemq.com/blog/mqtt-essentials-part
19
Techscripts