issue is with the socket.

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
emmajames
Posts: 1
Joined: Fri Oct 29, 2021 8:00 am

issue is with the socket.

Post by emmajames » Fri Oct 29, 2021 8:06 am

Hello, everyone. I'm trying to use Micropython to create an ESP8266 device that hosts a web server and runs a process. I'd like a start button on the hosted website that starts a procedure.  I'd like a stop button on the web page to halt the events before they finish.

My issue is with the socket.

accept() is a blocking function. So, if I listen for the next web request after beginning the relay process, execution stops while waiting for the socket. accept().

I'm trying to come up with a solution that goes 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()

An event state object would be used to communicate between the web server and the relay event loop. My issue is that socket.accept() in web server() still blocks, even when invoked from an asyncio task.

I also tried using s.setblocking(0) to make the socket nonblocking. The blocking was resolved, but the page would not render and an exception would be thrown.

Is uasyncio the appropriate library for this task? Is it possible that I'm on the wrong track?
Many thanks,
payday loans

Post Reply