Book Image

ESP8266 Home Automation Projects

By : Catalin Batrinu, Constantin Tambrea
Book Image

ESP8266 Home Automation Projects

By: Catalin Batrinu, Constantin Tambrea

Overview of this book

The ESP8266 is a low-cost yet powerful Wi-Fi chip that is becoming more popular at an alarming rate, and people have adopted it to create interesting projects. With this book, you will learn to create and program home automation projects using the ESP8266 Wi-Fi chip. You will learn how to build a thermostat to measure and adjust the temperature accordingly and how to build a security system using the ESP8266. Furthermore, you will design a complete home automation system from sensor to your own cloud. You will touch base on data monitoring, controlling appliances, and security aspects. By the end of the book, you will understand how to completely control and monitor your home from the cloud and from a mobile application. You will be familiar with the capabilities of the ESP8266 and will have successfully designed a complete ready-to-sell home automated system.
Table of Contents (16 chapters)
Title Page
About the Author
About the Reviewer
Customer Feedback
Building a Home Thermostat with the ESP8266
Using ESP8266 to Build a Security System

Securing a connection between ESP8266 and an MQTT broker

If you don't want to have your own broker, but you want a secure MQTT connection you can use a cloud MQTT instance, such as

First create an account on and confirm your email address. After that you can log in to and get your private assigned topic. It is an eight character code, such as c5c05211, and this code needs to precede all of your topics as follows:


No matter if you publish or subscribe. The following code connects to the Wi-Fi and then establishes a secure connection to the cloud MQTT over port 8883. Every message sent to the broker is received back like a loopback.

Included header files are the ESP8266WiFi and the PubSubClient MQTT class:

#include <ESP8266WiFi.h> 
#include <PubSubClient.h> 

GPIO 12 will be used later to blink a LED every time a message is received and GPIO 13 will be changed to HIGH every time a...