As the title says... Chat on...

User avatar
By ESP-12f
#55515 Hello folks,

I am trying to wait for a couple of seconds in my script. Similar to sleep function in other languages.
I tried tmr.delay(5000) to sleep for 5 seconds. But this does not work.

Any suggestions?
User avatar
By marcelstoer
#55537 http://nodemcu.readthedocs.io/en/latest ... /#tmrdelay

Busyloops the processor for a specified number of microseconds.
This is in general a bad idea, because nothing else gets to run, and the networking stack (and other things) can fall over as a result. The only time tmr.delay() may be appropriate to use is if dealing with a peripheral device which needs a (very) brief delay between commands, or similar. Use with caution!


The delay shouldn't be more than 50μs(!) if I'm not mistaken.

You need to familiarize yourself with the asynchronous, event-driven nature of NodeMCU. tmr.alarm() is probably what you're looking for.