Internet of Things done cheaply with ESP 8266

For some time I had an idea to do few “home improvements” and, as a side effect, learn a bit about microcontrollers and electronics. So called “smart home” can be expensive - there are a lot of out-of-the-box solutions that cost a small fortune (as I said: “for some time”, now it is cheaper). So my idea really was: can I do it as cheap as possible?

After some research I decided to build my solution around some central software working on Raspberry Pi 3 and some amount of sensing- and command-nodes built with some cheap MCUs and radio transmitters, maybe even battery powered. My initial choice was to use AVR microcontrolers (yes, the ones from Arduino) and cheap NRF24L01 transceivers.

I wanted to build something looking like star (see diagram):

Initial topology

So I’ve purchased several RF24 modules, few AVR, two Arduino Uno modules, a bootloader burning shield and even built a few prototype devices. But I also found several problems:

  1. NRF24L01 has serious limitation - only 1 transmitting channel and only 4 receiving channels. That means I can use only up to 4 devices in star topology!
  2. When used within building, the range of RF is seriously limited - star topology is anyway not achievable.
  3. Each device must have unique address, so if I don’t want to have this address configurable, I would most likely need an option to configure node (i.e. by pressing magic button while resetting).

Each of this problem is apparently solvable: you build mesh network out of RF24 modules, you can implement nice configuration capability via a serial interface, you can store configuration in EEPROM, etc. But this will consume more and more time to develop and test and if I don’t have quick results, I easily get tired and annoyed. So the project was de facto suspended for few years.

Until I’ve accidentally heard of ESP 8266 thing…

ESP 8266 is a tiny and cheap WiFi module with complete TCP/IP stack. It can be used with Arduino or other systems lacking its own radio capabilities. It was soon discovered, that ESP module itself has microcontroler capability that are significant. It contains 32 RISC microprocessor, runs at 80MHz, over 64KiB RAM and up to 16MiB Flash Memory support. There are 16 GPIO pins (typically 10 are available) and one ADC pin. This is more than enough for most of applications, and relatively big processing power and memory allows unusual as for microcontroler capabilities of running HTTP web server.

The built in WiFi transceiver allows completely new network topology to be used. It runs on WiFi infrastructure that most of our homes are equipped with:

WiFi topology

I decided to make my life even easier and installed specialized firmware on my Raspberry called Home Assistant (see 1). Home Assistant deserves separate post, I will just mention a few killing features:

  1. It runs web server and has nice, configurable web GUI.
  2. The GUI is both responsive (looks good on mobile) and progressive (PWA) - that means it can install and look almost like native smartphone app.
  3. Sophisticated configuration capabilities allow for complex automations.
  4. It contains MQTT broker that makes integration with ESP based nodes seamless.

Home Assistant Dashboard

All this means we can build a very complex home automation in days. It can have a very modern, event based architecture and be completely configurable via web with any web browser.

There are many ways the ESP 8266 module can be programmed. One can use Arduino IDE with appropriate plugin or use Lua programming language with specialized firmware called NodeMCU. For lazy people there are dedicated firmwares that require (almost) no programming. Amongst them the most popular are Tasmota and ESP Easy. In next posts I will focus on the latter.

ESP Easy allows for easy click-thru configuration via web for most of use cases:

ESP Easy devices

This is more than sufficient if we use Home Assistant as a brain of our devices. But we can also make our nodes more smart and autonomous with so called rules, which is in fact a very simple, event oriented programming language:

ESP Easy rules

In next posts I will make you more familiar with smart home architectures, instalation and configuration of ESP Easy firmware as well as with rules language.

References