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

User avatar
By cwr
#55386 A common way of handling small embedded applications is with a state machine:
Code: Select allwhile (true) {
    switch (state) {
    case a: do_a()
            state = b
    case b: do_b()
            state = c
    case c: do_c()
            state = a
    }
}

Obviously this doesn't work in NodeMCU as it is written, but it's fairly
straightforward to reduce the individual cases to timers and callbacks.
What I can't see is how to remove the main while() loop. Apparently running
such a loop continuously blocks out the underlying Espressif software, and
the application hangs.

How do you handle a continuous main loop on the ESP8266? (Converting the
individual cases isn't a problem.)

Thanks - Will
User avatar
By marcelstoer
#55408 I'm not sure I fully understand your problem but NodeNCU ain't Arduino. Usually you start by registering callbacks for certain events (e.g. GPIO triggers, requests from clients, etc.) and/or certain intervals (e.g. read sensor value every n minutes). tmr.alarm() might be of interest for you.
User avatar
By devsaurus
#55448 As marcelstoer mentioned, there's no equivalent of Arduino's main loop in the nodemcu firmware.
Maybe post some specific example code that shows the use case for such a continuous loop.
User avatar
By cwr
#55475 The underlying problem is the need for a non-blocking delay, eg: waiting for a timer
to fire. Obviously a Lua "while (true)" won't cut it - it locks out the underlying firmware,
and hilarity ensues. I've tinkered with co-routines, but they don't seem to be the
solution. Possibly Lua's tail recursion holds the answer. I'll keep tinkering.

Thanks - Will