The Hub 3 - an ESPNow to Wifi/MQTT Gateway

by MrDIYLab in Circuits > Microcontrollers

2079 Views, 5 Favorites, 0 Comments

The Hub 3 - an ESPNow to Wifi/MQTT Gateway

system3.png

They are all finally here! A new hub, a new door & window sensor and a brand new temperature sensor. The whole system works together to provide a very fast response time for door, window and temperature sensors. For example, the door sensor is capable of reporting the change in the door position, open or closed, in around a fifth of a second. Which means this can used in a home automation system to turn on a light almost immediately as I open a door.

I will discuss the door, window, and temperature sensors in a different articles but here I will focus on the new version of the hub! The Hub3

Watch the Video

The Hub 3 - an ESPNow to Wifi gateway

The video walks through the changes from version 2. Feel free to add your questions in the comment section of the YouTube video if you need any further assistance.

Hub 2

gateway.png

In the previous hub version, Hub 2, I went from using 2 Wemos d2 minis to a custom design. I added more peripherals and updated the UI and firmware. In the Hub3, I took this a step further with more enhancements and firmware features.

The main purpose of the hub is to take messages coming from the sensors using ESPNow and gateway them to an MQTT server. It also offers the sensors status over HTTP and provides a graphical interface to show the status of all the connected sensors.

The previous version didn’t have a place to permanently store data which meant that all the sensor information was kept in memory and when the hub rebooted it had to wait to rebuild the sensors list as they come in. I could have used the EEPROM on the device to save these statuses but as you might already know, the ESP8266 doesn’t have real EEPROM. Instead it emulates flash and flash has a very low write count. Meaning if I have kept saving the data for every single sensor update, the ESP8266 flash will probably be destroyed by now. That is why I opted to keep the data in memory instead.

SD Card Module

hardware.png
sdcard.png
door.png
temp.png

In the new Hub 3, I added an SD card module. This allows me to save the sensors list to a file. And more importantly, I was able to use the sd card to save the sensor’s entire history and log every update. So in the Hub3, each sensor will have a dedicated file on the sd card with all its data. This opens the door to a whole new range of possibilities.

For example, on the web interface, I can do fancy things like showing the activities of a door for an entire today ( see picture above). I divided the day into 24 blocks and showed different colours to represent the activities density. For example, this door was most actively used in the red colored hours and a bit less in the yellow hours and not at all in the blank hours. Another example,(see picture above), for a temperature sensor. I was able to plot the temperatures through the day.

Also, the sensors have actual names and not just IDs like before.This is because I used the sd card again to assign names to the sensors and save them in a file. When I only had a handful of sensors, I was able to differentiate between them but, as the list got bigger, that became a bit of a challenge and needed a solution. Having an sd card definitely made that a possibility.

ESP07S Receiver

schematic_hub.png

Another change I made to the hub was the receiver. Previously I used an ESP-01 module but now I am using the ESP-07S module. This should have a positive impact on the range as it allows the use of external antennas and as a side bonus, contrast the EPS-01, it has a shield and is FCC approved.

This change introduced a small challenge though: how will I be able to program both esp8266 modules in place? They are both connected using Rx & TX which are also used for programming. I solved this by adding jumpers for RX and TX so I can disconnect them when needed. Most of the time I use the built-in OTA feature in the firmware to upload new code but in the rare event that doesn’t work, I have a backup. This is also handy when I initially flash both modules. That is why, in the Hub 2, I didn’t solder the ESP-01 to the board and kept it detachable on a 2x4 socket. A kinda cool side effect of not using standoffs is it decreased the hub physical height, making it slimmer and the display is now much closer to the top.

I also made two further small changes. The first was ditching the buzzer altogether. It is far more convenient to receive alerts on the phone using a home automation system. The second was adding an option in the configuration page to let the display go to sleep and turn off completely when it is idle.

PCBs

pcbway.png

A shoutout to PCBWay for providing these PCBs for my project. I have been using their service for over 3 years and had nothing but great experience and quality. If you are a hobbyist and in the market for PCBs, I highly encourage you to give them a visit. Get 10 PCBs for $5 USD at https://www.pcbway.com

Conclusion

And that wraps up the Hub3. The source code and schematics can be found on my GitLab repo.

I made a small batch if you want to buy the Hub3 at my shop and experiment - https://store.mrdiy.ca/p/thehub_ver3

Thanks for reading!

If you found this useful, maybe consider visiting my YouTube channel and say hello.