Introduction: Super Simple ESPNow to Wi-Fi / MQTT Gateway

About: I am a techie DIYer who loves tinkering with electronics. Twitter @MrDIYca. For more info and my full contacts, please visit www.MrDIY.ca

My Hub is an ESPNow to Wi-Fi gateway. I made it available on my store and it has lots of bells and whistles but if you are looking for a functional minimalistic hub that you can build at home then this article is for you.

Step 1: Watch the Video

The video walks through the steps on how to build the hub. Feel free to add your questions in the comment section of the YouTube video if you need any further assistance.

Step 2: Introduction

I added extra functionalities to my hub, to be able to view my sensors at a glance, and have the ability to save their data to files on an SD-Card. But the main or core purpose of the hub is to get way ESPNow messages to MQTT over Wi-Fi. So in this video, I will take it back to the basics and show you how you can build the core hub at home.

For this, you'll need two ESP8266 modules or boards. I have used the Wemos d1 mini boards and had no issues so far. The first board will be used as the ESPNow receiver and the second one will be used to maintain the Wi-Fi connection and send MQTT updates to your server.

Step 3: Why 2 ESP8266 Boards?

Some have asked me why I use two boards and can I simply use one. The answer is yes. It is doable. But there are limitations that require extra efforts to make it work. For instance, the channel # used by ESPNow must match the Wi-Fi channel. Otherwise, ESPNow fails to initiate. And since the Wi-Fi channel is changed frequently by the access points or home routers, the code needs to address that. the senders also need to be aware of that change which involves scanning-before-sending ESPNow. This adds extra time and consumes more battery for the sensors. by using two ESP modules, I can keep the ESPNow channel static and let the wi-fi channel roams.

Step 4: Hardware

The wiring is very straightforward Tx to Rx, Rx to Tx, Gnd to Gnd and Vcc to Vcc. You will be able to program these boards as you normally do.

Step 5: Firmware

I have taken the code made for the hub 3 and stripped it down to the bare functionalities. And here is the resulting source code.

There are two files one for each Wemos d1 mini (or whatever board you picked for the hub). The first is the receiver.ino. it doesn't require any configuration. Simply flash the code as is. The second one is the gateway.ino. this file requires some changes. You will need to enter your wi-fi ssid, password, mqtt server, username and password. Once these are updated in the code, it can be flashed to the second board.


If you are using the same ESPNow data structure as mine, then you should have a functional ESPNow to MQTT gateway right out of the box. But if you want to use your own then you might need to go back to the gateway code and make your changes there to fit your needs. the good news is the receiver doesn't require any alteration because the receive data is sent as is.

Step 6: PCBs

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

Step 7: Conclusion

So that's it. You should have a functional ESPNow to mqtt gateway. if you want to learn more about my hub, I will link to some of my previous videos down below. if you are interested in building my hub3, I still have some PCBs available on my store - https://store.mrdiy.ca/p/thehub_ver3_pcb

You can download the source code here.

Thanks for reading!

If you found this useful, maybe consider visiting my YouTube channel and say hello. I will be posting future updates about this project.