You are on page 1of 6

Transactions on Engineering and Sciences ISSN: 2347-1964 (Online) 2347-1875 (Print)

Vol.3, Issue 6, October-December 2015

Low Cost Home Automation with ESP8266 and


Lightweight protocol MQTT
Krupal Kachhia Patel1 Jignesh Patoliya2 Hitesh Patel3
1PG Scholar, Embedded & VLSI Design, CSPIT, CHARUSAT, India.
2&3Faculty of Electronics & Communication, CSPIT, CHARUSAT, India
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) Confirmable: A request message that requires an acknowledgement (ACK).
2) Non-confirmable: A message that does not need acknowledged.
3) Acknowledgment: It conforms the reception of a confirmable message.
4) Rest: It conforms the reception of a message that could not be processed.
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
Transactions on Engineering and Sciences ISSN: 2347-1964 (Online) 2347-1875 (Print)
Vol.3, Issue 6, October-December 2015
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.

Figure 1: Publish / Subscribe Architecture [5]


For example temperature sensor that senses the data of temperature and publishes whatever they have
to Hive-MQ broker. Hive-MQ broker is one type of free online broker. Now here client side has two devices
which are laptop and mobile phone. These both have subscribed temperature topic so that whatever the
data of temperature that send through broker to these two devices. So this way server has to publish data
and client has to subscriber the particular topic to get that data. So this is publish/subscribe architecture. A
very good example of MQTT protocol is Facebook Messenger.
III. ESP8266 OVERVIEW
The ESP8266 is the name of microprocessor designed by Espressif system. Espressif is a Chinese
company based out of Shanghai. The ESP8266 is a Wi-Fi device capable of running self-contained
application. There are a variety of boards styles available for ESP8266. Here important thing is there is only
one ESP8266 processor and it is this processor that is found on all breakout boards. [1]
A. ESP- 01
The Esp-01 board is an ESP8266 on an 8 pin board.

Figure 2: ESP8266 01 module Pin Diagram [1]


The pin out of the device is as follows:
Table 1: Esp 01 Pin
Function Description
TX Transmit
RX Receive
CH_PD Chip enable [0- Disable, 1- Enable]
GPIO 0 Should be HIGH on boot , LOW for flash update
GPIO 2 Should be HIGH on boot
RST External Reset [0 Reset, 1 Normal]
VCC 3.3V
GND Ground

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
Transactions on Engineering and Sciences ISSN: 2347-1964 (Online) 2347-1875 (Print)
Vol.3, Issue 6, October-December 2015

Figure 3: ESP8266 12 module Pin Diagram [1]


Table 2: Esp 12 Pin
Function Description
TX Transmit
RX Receive
CH_PD Chip enable [0- Disable, 1- Enable]
GPIO 0 Should be HIGH on boot , LOW for flash update
GPIO 2 Should be HIGH on boot
GPIO 13 Also used for SPI MOSI
GPIO 12 Also used for SPI MISO
GPIO 14 Also used for SPI clock
GPIO 16
ADC Analog Pin
GPIO 4 Regular GPIO
GPIO 5 Regular GPIO
RST External Reset [0 Reset, 1 Normal]
VCC 3.3V
GND 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:

Figure 4: ESP8266 wit TTL Connection


If this work correctly then no problem, In case module does not response then we have to update
ESP8266 firmware that is available on ESPSITE. For firmware update you might download software
named ESP8266 FLASHER. Open the software then load the bin file after that select com port and last press
flash button.
Now whenever program has been dumped in ESP module at that time we must connect GPIO 0 to
Ground. After the program is being loaded remove GPIO 0 form the ground and it is necessary.
B. Software Part
Different type of software and programing language are used for programing in ESP8266 Wi-Fi module.
This paper has used Arduino IDE software for programing in ESP8266. Arduino IDE is most common very
easy to learn and very simple to understand software available on the market. This is open software you can
download the latest version is 1.6.5 on official website www.arduino.cc.

16 Techscripts
Transactions on Engineering and Sciences ISSN: 2347-1964 (Online) 2347-1875 (Print)
Vol.3, Issue 6, October-December 2015
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:
Open the setting.
Enter URL : test.mosquitto.org
Port: 1883
Here Username and Password Optional its use for authentication.
Go to Subscribe and Add TOPICS which are listed below.
Once all the topics were subscribe then go to Publish and publish data or status on particular topic.
Application is shown here:

Figure 5: Android MyMQTT application Configuration for online mode


i. Mode Selection
TOPIC: mode
DATA: Online Go to online mode
Offline Go to offline mode
ii. Light On Or Off
TOPIC: led
DATA: On Turn on light
Off Turn off light
iii. Fan On or Off
TOPIC: fan
DATA: On Turn on fan
Off Turn off fan
iv. Check the status of lights or fans
TOPIC: status
DATA: Led Status for light which is on or off
Fan Status for fan which is on or off
v. Change SSID and PASSWORD
TOPIC: SSID
DATA: ssid

TOPIC: PASS
DATA: pass
vi. Reset all configuration

17 Techscripts
Transactions on Engineering and Sciences ISSN: 2347-1964 (Online) 2347-1875 (Print)
Vol.3, Issue 6, October-December 2015
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:
Open the application and write IP Address which is 192.168.4.1.
Enter the port number which is 8080.
Click on that configuration.
This configuration is shown in figure.

Figure 6: Android TCP Client application Configuration for offline mode


Here in offline mode no topics are available but I choose same topic name for controlling home
automation.
i. Mode Selection
Online Go to online mode
Offline Go to offline mode
ii. Light On Or Off
Ledon Turn on Light
Ledoff Turn off Light
iii. Fan On or Off
Fanon Turn on Fan
Fanoff Turn off Fan
iv. Check the status of lights or fans
Statusled Status of Light
Statusfan Status of Fan
v. Change SSID and PASSWORD
Ssid = ssid
Pass = pass
vi. Reset all configuration
Rst Reset all configuration
VI. CONCLUSION AND FUTURE WORK
This paper is described architecture and implementation of home automation system. The implemented
system uses basic electronic development boards to minimize the system development cost. Apart from this
the low cost, the smartness of the automation system can be justified with the automation scripts that can be
customized by the user, even at runtime. The complete system efficiently utilizes the existing network
infrastructure with the help of MQTT protocol and TCP protocol. The ESP8266 Wi-Fi module only provides
a single analog input, which creates difficulty in interfacing multiple analog sensors. The issue can be

18 Techscripts
Transactions on Engineering and Sciences ISSN: 2347-1964 (Online) 2347-1875 (Print)
Vol.3, Issue 6, October-December 2015
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. 268-
275.
[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

You might also like