import socket from machine import Pin led_pin = Pin(10, Pin.OUT) def web_page(): return """<html> <head> <title>ESP32 webserver met led</title> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <h1>ESP32 webserver met led</h1> <p><a href="/?led=aan"><button>AAN</button></a></p> <p><a href="/?led=uit"><button>UIT</button></a></p> </body> </html>""" server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.bind(("", 8080)) server_socket.listen(5) while True: connection, address = server_socket.accept() print("Got a connection from %s" % str(address)) request = str(connection.recv(1024)) print("connect = %s" % request) if "/?led=aan" in request: print("LED AAN") led.value(1) if "/?led=uit" in request: print("LED UIT") led.value(0) response = web_page() connection.send("HTTP/1.1 200 OK\n") connection.send("Content-Type: text/html\n") connection.send("Connection: close\n\n") connection.sendall(response) connection.close()