uPython Crash if Blynk Server Goes offline

I am using an ESP8266 as an IOT controller. All is working, but I need to make it bulletproof. If my local blynk server is down when the ESP8266 powers up, it exits micropython with an error.

I’m looking for a way it will loop/wait indefinitely for the blynk server to come up (without overloading the stack like my recursive try/except loop does).

I would also like a similar indefinite loop/wait if the server goes down at a later time (although this one seems easier since the blynk “object” is already established and I can probably use things like blynk.connect() to test for a connection - I can’t make this work if the server is down on boot)

Any help would be much appreciated!


Are you fully committed to MicroPython?
I’d say that the Blynk C++ library is probably much more mature, and certainly has a much larger user base, so you have more programming methods available to you.

Having said that, if you are building a home automation system then my preference is not to run any Blynk code on your ESP devices at all, but instead to use MQTT messaging and run Node-Red with the Blynk plugin on a suitable local server.

Using that approach would enable you to still run MicroPython on your ESPs, using a suitable MQTT library. Node-Red and the MQTT broker can happily run alongside a local Blynk server running on a Pi.


1 Like

Thanks. Yes to uPython - I started with C++ on the ESP8266s, but uPython has proven to be hugely advantageous to me: WEBREPL, OTA update of files, cross-platform execution and debug, plus I can code python so much faster than I can C++ (I use it everyday for my real work).

Having said that, I am willing to do what I can (if I can) to make Blynk & uPython play better.

For all my my applications, all I really need is a bulletproof connection to the Blynk server and the ability to write a virtual pin (integer is all I need) to an endpoint and to allow the endpoint o push a virtual pin integer back, as well as be polled to read a virtual pin integer by the server/app. Which is less than the current Blynk library is attempting to provide. I’ll give up features for reliability and simplicity.

I have not ruled out MQTT, but I love the Blynk app flexibility and ease with which I can share apps to different phones. I realize node-red can bridge that gap, but I have had some sucess reusing my python code from the endpoints on my server to do the bridging. My server python blynk code has been working flawlessly (easy to auto-connect, etc). The ESP python code is close, but having some issues with virtual sync no working when I reconnect after testing a server reboot.


I wasn’t suggesting that you stop using the Blynk app.
Node-Red provides the bridge between the Blynk server/App and MQTT, so you keep using the app/sever in exactly the same way, but the code that you run on your devices contains no Blynk code, simply WiFi and MQTT code.