So here is my history:
I'm writing my own neopixel version, using webserver polling method to change the neopixel pattern.
So needed to change the behave of a coro during run time.
I did not find any code examples so far, so I create my own and that works!
The problem is; ESP8266 hangs after a long while running perfectly, say after one hour or more.
It hangs by itself, during running alone, no webserver access.
Exception messages is not suppressed.
No error message printed, it just stop blinking and answering the web requests.
I'm able to use ctrl+c on thonny.
My question is:
Is it the right way to change a running coro?
Or am I doing it wrong?
Code: Select all
# A global variable ( mode ) holds the name of the class with contains different patter each one.
# It is modified by webserver request handler every time the user change it on web page.
# ( this_mode ) is the default mode after reboot.
mode = Stars
async def blink(this_mode, period_ms):
m = this_mode()
while True:
m.run()
if this_mode != mode:
this_mode = mode
m = mode()
gc.collect()
await uasyncio.sleep_ms(period_ms)
def main():
wlan = do_connect()
myip = wlan.ifconfig()[0]
socket_listen()
event_loop = uasyncio.get_event_loop()
event_loop.create_task(serve_requests(myip, handler, 50)) # 50
event_loop.create_task(blink(mode, 50))
event_loop.run_forever()
gc.collect()
main()