simple Server using socketpool on a pico w with Circuitpython

36 Views Asked by At

this is my code:

import wifi
import socketpool

wifi.radio.connect("ssid", "password")
print("connected")

pool = socketpool.SocketPool(wifi.radio)


# Create a simple HTTP server function
def simple_http_server():
    server_socket = pool.socket()
    server_socket.bind((str(wifi.radio.ipv4_address_ap), 80))
    server_socket.listen(1)

    print("Server is listening on {}:80".format(wifi.radio.ipv4_address))

    while True:
        print("Waiting for a connection...")
        client_socket, client_address = server_socket.accept()
        print("Accepted connection from:", client_address)

        client_socket.send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n")
        client_socket.send("<html>Hello, World!</html>\r\n")
        client_socket.close()

The output I get when I call simple_http_srever is: Server is listening on 192.168.68.102:80 Waiting for a connection... but i cannot connect to the server on any device in the same network. I get no response and it doesnt print Accepted connection from: ...

It worked once somehow but now not anymore. I tried a few setups and simplified the code a lot, ended up using this online example

0

There are 0 best solutions below