So I built a wifi garage door controller using an ESP8266 board (D1 Mini). The hardware just uses relays to control the doors and reed switches to sense whether or not the doors are open or closed. I did the project in phases.
Phase 1 was to build the hardware and just have it working with Blynk. This worked great and I could control open/close and see the garage door status on my phone. I did this with just the basic Blynk.begin(auth, ssid, pass) statement in the setup and Blynk.run() in the loop. This worked great and I had it running for several months just like this while I worked on the Phase 2 portion.
Phase 2 was to keep this functionality but also add in MQTT control so that I could integrate it into my Home Assistant installation that is running on my raspberry pi (running mosquitto MQTT server). I was able to get all of the control working correctly and have it both be controlled by Blynk or HA. To do this, I kept the normal Blynk.run statement in the loop, but changed the setup to be Blynk.config(auth) instead as I had already connected to wifi with the other standard WiFi.begin(ssid, password) statements seen in many examples. I then added the logic to look at the reed switches and send MQTT messages for status and also look for MQTT messages to open/close the garage door.
Initially, everything seemed to be working correctly. The problem was that I would lose wifi connection every 1-2 days and the ESP8266 would not reconnect to the network without a power cycle. I tried to include statements in the loop to reconnect to wifi if it disconnects, but nevertheless I would lose connection after 1-2 days and be dead in the water again until a power cycle. I rolled back the code to just the Blynk functionality and the connection is steady as a rock again.
So I guess my question is, is there something magical about the Blynk library to be able to maintain a steady wifi connection? And if so, is it possible to have Blynk directly send the MQTT messages to my home automation platform? I’ve tried to read into this a bit, but it seems the MQTT functionality with Blynk isn’t well documented. There seemed to be other workarounds like using node red in the middle as a translator between HA and Blynk, but I’m not sure if this is the right way to go or not.
I can post the full code if that would help, but seeing as how I’m a hardware engineer by trade, it’s not the prettiest.
Any help would be appreciated, thanks!