Применяем код с урока №4, для работы WEB странички на языке microPython и Arduino Ide.

from machine import Pin

led = Pin(2, Pin.OUT)
led.value(0)

def web_page():
html = """<html><head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>body {max-width: 300px;margin: 0px auto;}
.switch {position:relative;display:inline-block;width:120px;height:68px}
.switch input { display:none }
.slider{position:absolute;top:0;left:0;right:0;bottom:0;background-color:rgb(190, 8, 8);border-radius:34px}
.slider:before{position:absolute;content:"";height:52px;width:52px;left:8px;bottom:8px;background-color:rgb(19, 17, 17);
-webkit-transition:.4s;transition:.4s;border-radius:68px}
input:checked+.slider{ background-color:#37e714 }
input:checked+.slider:before {-webkit-transform:translateX(52px);-ms-transform:translateX(52px);
transform:translateX(52px)}
</style><script>function toggleCheckbox(element){var xhr = new XMLHttpRequest();
if (element.checked) { xhr.open("GET", "/?led=on", true);}
else { xhr.open("GET", "/?led=off", true); }
xhr.send();}
</script>
</head><body><h1>ESP Web Server</h1><label class="switch">
<input type="checkbox" onchange="toggleCheckbox(this)" %s>
<span class="slider"></span>
</label>
</body></html>"""
return html

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('',80))
s.listen(5)

while True:
try:
if gc.mem_free()<102000:
gc.collect()
conn, addr = s.accept()
print('Got a connection from %s' % str(addr))
request = conn.recv(1024)
conn.settimeout(None)
request = str(request)
print ('Content = %s' % str(request))
led_on = request.find('/?led=on')
led_off = request.find('/?led=off')
if led_on == 6:
print ('LED_ON')
led.value(0)
if led_off == 6:
print('LED_OFF')
led.value(1)
response = web_page()
conn.send('HTTP/1.1 200 Ok\n')
conn.send('Content-Type: text/html\n')
conn.send('Connection: close\n\n')
conn.sendall(response)
conn.close()
except OSError as e:
conn.close()
print('Connection closed')