BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Using Micropython lib w/o the main/endless loop

Hello,

I’m using Blynk in a Mycropython project on ESP8266. I don’t have a “main / endless” loop in my application. Rather a few (2 for the moment) timers. The main one runs each 1 sec, it does logic then it reschedules for one second again. One reason of using a timer instead of a main loop is that I’m using REPL/WebREPL. If I start a blocking/endless loop, REPL continues to work (I guess thanks to underlying RTOS scheduling magic simulating multi threading), but on reconnect to REPL the main loop is halted.

My main timer looks like this:

def loop():
	try:
		blynk.run();
		# my code here ...
	finally:
		timer.init(period=LOOP_TIMER_PERIOD_SEC * 1000, mode=Timer.ONE_SHOT, callback=lambda t:loop());

Is this way of usage tolerated by the lib? Or in other words is there something I can do to so that the lib accepts my call to “blynk.run()” from a timer rather than an endless loop? I observe the following things:

  • Some times the lib is disconnected. The max connected period was about 3 hours. However, calling “blynk.connect()” usually works. I didn’t try leaving the board on w/ a main loop, to see if these disconnections still occur. Most of the disconnections (I’m not sure for all of them) are preceded by some exceptions printed to the console about ENOMEM
  • When Blynk widgets read from the board: there is no noticeable lag. But when a button widget writes to the board, there is about 5 to 10 sec delay before the notification gets to the board. And the main timer fires each 1 sec

Thanks in advance for your feedback.
Best regards,
Cristian