Micropython question using uasyncio with ESP8266 webserver
Posted: Tue Oct 27, 2020 4:53 pm
Hi all. I am trying to build an ESP8266 device with micropython that hosts a web server and runs a process. From the hosted web site, I want a start button that triggers a process (in this case a series of events from a series of relays that would take minutes to complete). I would like the web page to have a stop button to halt the events before they complete.
My problem is socket.accept() is blocking. So after starting the relay process, if I listen for the next web request, processing stops while waiting for socket.accept().
I am trying to solve this with something like this:
import uasyncio as asyncio loop = asyncio.get_event_loop() loop.create_task(web_server()) loop.create_task(relay_event_loop()) loop.run_forever()
The web_server and relay_event_loop would communicate with each other via an event_state object. My problem is that in web_server(), socket.accept() is still blocking, even when called from an asyncio task.
I also tried setting the socket to nonblocking (s.setblocking(0)). This solved the blocking, but the page would not render and would fall into an exception state.
Is uasyncio the right library for this? Or am I completely going down the wrong path?
My problem is socket.accept() is blocking. So after starting the relay process, if I listen for the next web request, processing stops while waiting for socket.accept().
I am trying to solve this with something like this:
import uasyncio as asyncio loop = asyncio.get_event_loop() loop.create_task(web_server()) loop.create_task(relay_event_loop()) loop.run_forever()
The web_server and relay_event_loop would communicate with each other via an event_state object. My problem is that in web_server(), socket.accept() is still blocking, even when called from an asyncio task.
I also tried setting the socket to nonblocking (s.setblocking(0)). This solved the blocking, but the page would not render and would fall into an exception state.
Is uasyncio the right library for this? Or am I completely going down the wrong path?