Skip to content

Instantly share code, notes, and snippets.

@hierophect
Last active January 9, 2021 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hierophect/5bb6133a69f8395841531013d46d2703 to your computer and use it in GitHub Desktop.
Save hierophect/5bb6133a69f8395841531013d46d2703 to your computer and use it in GitHub Desktop.
ESP32S2 Server
import wifi
import socketpool
# connect to wifi
wifi.radio.connect("YOURNETWORK", "YOURPASS")
pool = socketpool.SocketPool(wifi.radio)
print(wifi.radio.ipv4_address)
HOST = wifi.radio.ipv4_address
PORT = 80 # Port to listen on
# make socket
sock = pool.socket(pool.AF_INET,pool.SOCK_STREAM)
sock.bind((HOST, PORT))
sock.listen(1)
conn, addr = sock.accept()
with conn:
print('Connected by', addr)
buff = bytearray(128)
numbytes = conn.recvfrom_into(buff)
if numbytes:
print(buff)
while True:
pass
@dglaude
Copy link

dglaude commented Jan 9, 2021

Now I feel the need for having a CircuitPython way to update some Dynamic DNS thing, or some "Bonjour", or to make sure that it register a name when doing DHCP. That way, without doing some static allocation in your DHCP server, you could "find" your board and talk to it.

How close is this API from the Python Network API so that existing piece of software server can be ported?

@hierophect
Copy link
Author

I'm probably not the right person to ask about that, unfortunately, I'm still very new to the Socket API. But I'll try and do some research about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment