Skip to content

Instantly share code, notes, and snippets.

@AXKuhta
Created November 24, 2022 14:29
Show Gist options
  • Save AXKuhta/0685e887a5a27e14032729277624a728 to your computer and use it in GitHub Desktop.
Save AXKuhta/0685e887a5a27e14032729277624a728 to your computer and use it in GitHub Desktop.
Nucleo F746ZG Micropython HTTP
import network
import socket
x = network.LAN()
x.active(True)
print(x.ifconfig())
ListenPort = 80
Host = ''
MainSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
MainSocket.bind((Host, ListenPort))
MainSocket.listen(0)
while True:
print("Waiting for connections...")
Client, Addr = MainSocket.accept()
print("New connection!")
while True:
line = Client.readline()
if line == b"\r\n":
break
print(line)
Client.send(b"HTTP/1.0 200 OK\r\n")
Client.send(b"Content-Length: 5\r\n")
Client.send(b"\r\n")
Client.send(b"Hello")
Client.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment