-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
CircuitPython version
Current main branch. https://github.com/adafruit/circuitpython/commit/b56d5d97d2ecdd11adb270770beabd0ed96c9c15Code/REPL
# Using adafruit_httpserver.py from https://github.com/adafruit/Adafruit_CircuitPython_HTTPServer/blob/ba2da4352290b880592ae5ab5db83ee50c045244/adafruit_httpserver.py
from secrets import secrets
import socketpool
import wifi
from adafruit_httpserver import HTTPServer, HTTPResponse
ssid = secrets['WIFI_SSID']
wifi.radio.connect(ssid, secrets['WIFI_PASSWORD'])
print("Connected to", ssid)
print(f"Listening on http://{wifi.radio.ipv4_address}:80")
pool = socketpool.SocketPool(wifi.radio)
server = HTTPServer(pool)
@server.route("/")
def base(request):
return HTTPResponse(content_type="text/html", body="<html><body>Hello from pico w</body></html>")
# Never returns
server.serve_forever(str(wifi.radio.ipv4_address))Behavior
When I make an http request to the pi with curl, I get curl: (56) Recv failure: Connection reset by peer and my route handler is not called. I'm able to get it to work by modifying adafruit_httpserver.py to set the socket to blocking.
Changing False to True here fixes things and the http endpoint responds as expected:
Description
I'm aware that the pico w wifi code is under active development (thanks for the great work so far!), so I'm not sure if non-blocking sockets haven't been fully implemented yet or if this is a bug. Or maybe I'm using it wrong.
If you have any pointers, I'd be happy to look into debugging this. I'm unclear on how non-blocking sockets are supposed to work though. If I call socket.accept(), then socket.recv_frominto(), at what point is the socket's pbuf supposed to be populated?
Additional information
No response