julesmanigne / SmartHome

Build a Smart Home using ESP32

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Greenergy - ESP32 Smart Home

Greenergy

GitHub GitHub repo size GitHub last commit

Introduction

This project describes how to build a basic Smart station using a ESP32, a BMP388 (temperature sensor), DHT11 (humidity sensor), and some LEDs.

🛠️ Installation

On MacOS

🍺 Install HomeBrew

Homebrew (brew) is a free and open-source package manager that allows installing apps and software in macOS, depending on the user’s desire. It has been recommended for its simplicity and effectiveness in saving time and effort. Its famous description is “The missing package manager for macOS” Homebrew lets you avoid possible security problems associated with using the sudo command to install software like Node.

Installing Homebrew is straightforward as long as you understand the Mac Terminal. The Homebrew installation process guides through each step.

You need Xcode for some Homebrew tools, Xcode is a macOS integrated development environment (IDE). You can use it to make apps for all mac OSs, iOS, iPad OS, watch OS, and tv OS. To download and install it, run the following command in the Terminal:

xcode-select --install

Accept starting the installation and the license, it will be installed automatically.
Now, to install Homebrew automatically, run the below command for macOS High Sierra, Sierra, El Capitan, and earlier :

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

And run this command for MacOS Catalina, macOS Mojave, and macOS Big Sur :

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Homebrew is now installed, to make sure it is up to date you can run the following commmand : brew update

Install Node-RED

Node-RED can be used on all platforms that can run Node.js. Node-RED supports Node.js 0.10.x or later. It is recommended to use the LTS (long-term maintenance) version of Node.js. We will now use Homebrew to install Node.js and Node-Red.

Node.js

To install Node.js (npm will be installed with Node) run the following command :

brew install node

NodeJS-Install

Congratulations you’ve installed Node.js & npm, to check the version you can run the following commmand :

  • node -version
  • npm -version

If the Node.js version and npm are correctly installed, you’ll see the version name in the Terminal.

Node-RED

To install Node-RED you can use the npm command that comes with Node.js :

sudo npm install -g --unsafe-perm node-red

Once installed, you are ready to run Node-RED, you just have to start with the node-red command. At first boot, the necessary directories and files will be created automatically.

NodeRED-Start

Enter the IP address of the specified server, by default it will be 127.0.0.1:1880.

Install Mosquitto

Open a Terminal window and run the following command to request Homebrew to install Mosquitto :

brew install mosquitto

After the Mosquitto installation has been completed, run the following command in a new Terminal window to launch Mosquitto with the default configuration.

/usr/local/sbin/mosquitto -c /usr/local/etc/mosquitto/mosquitto.conf
  • To start the broker, run the following command : brew services start mosquitto
  • To stop the broker, run the following command : brew services stop mosquitto

Install Arduino

Get the latest version of Arduino from the download page. The file is in zip format, if you use Safari it will be automatically extracted. If you use a different browser you may need to extract it manually.

Then, copy the Arduino application bundle into the Applications folder (or elsewhere on your computer).

ESP-32

To install the ESP32 board in your Arduino IDE, follow these next instructions :
In your Arduino IDE, go to File> Preferences :

Enter the following into the Additional Board Manager URLs field :
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

Next, open the Boards Manager, go to Tools > Board > Boards Manager, search for ESP32 and press install button for the ESP32 by Espressif Systems. That’s it. It should be installed after a few seconds.

On Windows

Install Node-RED

Node-RED can be used on all platforms that can run Node.js. Node-RED supports Node.js 0.10.x or later. It is recommended to use the LTS (long-term maintenance) version of Node.js.

Node.js

First, you need to download the Windows Installer (.msi) file from the official Node.js website. This MSI installer database carries a collection of installer files essential to install, update, or modify the existing Node.js version.

Notably, the installer also carries the Node.js package manager (npm) within it. It means you don’t need to install the npm separately.

When downloading, select the correct version as per your operating system. For example, if you’re using a 64-bit operating system, download the 64-bit version, and if you’re using the 32-bit version, download the 32-bit version

Once you open and run the .msi file, the installation process begins. But you have to set a few parameters before running the installation process. The system will complete the installation within a few seconds or minutes and show you a success message. Click on the Finish button to close the Node.js installer.

Congratulations you’ve installed Node.js & npm, to check the version you can run the following commmand :

  • node --version
  • npm --version
Node-RED

To install Node-RED you can use the same npm command as MacOS that comes with Node.js :

sudo npm install -g --unsafe-perm node-red

Once installed, you are ready to run Node-RED, you just have to start with the node-red command. At first boot, the necessary directories and files will be created automatically.

Enter the IP address of the specified server, by default it will be 127.0.0.1:1880.

Install Mosquitto

Download Mosquitto from https://mosquitto.org/download/ and install it, if you install it with the “Service” checkbox checked, it will start automatically with Windows and occupy the default port 1883.

If you installed Mosquitto this way you can disable the service by going into the Services menu in Windows and pressing the stop button with the Mosquitto Broker selected.

The installation path is by default : C:\Program Files\mosquitto, navigate to the folder with cmd.exe using :
cd C:\”Program Files”\mosquitto

Running the command mosquitto.exe -v will start the broker. For more information check this tutorial : Mosquitto-Install

Install Arduino

Get the latest version of Arduino from the download page. You can choose between the Installer (.exe) and the zip packages. We suggest you use the first one that installs directly everything you need to use the Arduino Software (IDE), including the drivers.

With the zip package you need to install the drivers manually. The zip file is also useful if you want to create a portable installation.

ESP-32

To install the ESP32 board in your Arduino IDE, follow these next instructions :
In your Arduino IDE, go to File> Preferences :

Enter the following into the Additional Board Manager URLs field :
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

Next, open the Boards Manager, go to Tools > Board > Boards Manager, search for ESP32 and press install button for the ESP32 by Espressif Systems. That’s it. It should be installed after a few seconds.

Quick Start

Start Node-RED

Terminal

As mentionned abovve, to start Node-RED, you just have to run the node-red command :

NodeRED-start

(MacOS)

Localhost

In order to access to Node-RED in your browser (Chrome, FireFox, Safari, etc), enter the IP address of the specified server, by default it will be 127.0.0.1:1880. You should have something that looks like this :

NodeRED-browser

Start MQTT

Open your terminal again, enter the following command :

brew services start mosquitto

Subscribe to a topic

mosquitto_sub -t inTopic

With this command we subscribe to a topic called "inTopic", it means that we will received everything that will be published on the topic.

Publish to a topic

Then, we may want to publish something on the inTopic which can be done using this command :

mosquitto_pub -t inTopic  -m "hellow world"

Now that we set up Node-RED and MQTT we are ready to build our Smart Home.

Arduino

Now, we will be showing you how to build an Home Automation System Using Arduino that can control electrical devices. These include held lighting, air conditioning, garage doors, security cameras, motion sensors, energy control units and whether sensors as well.

So you may have heard about a thing called Arduino and you’re wondering what is this called Arduino? At its essence the Arduino is an electronics tool for making really cool things and people make all types of really awesome things.

In this project we will be using several parts that can be find here and if you need to see how we put them together, have a look at our schematic.

Node-RED flow

MQTT in

MQTT out

APIs

Schematic

ESP32 Smart Home

Parts :

  • 1x Breadboard
  • 1x ESP32 Dev board (/ ESP8266 NodeMCU)
  • 2x BMP388 Adafruit (/ BMP280)
  • 2x DHT11 (/ DHT22)
  • 6x LEDs

3D

📝 License

MIT-License

About

Build a Smart Home using ESP32

License:MIT License


Languages

Language:C++ 100.0%