# importando as bilbiotecas
from machine import Pin
from time import sleep
import network
try:
import usocket as socket
except:
import socket
redes = network.WLAN(network.STA_IF)
redes.active(True)
print(redes.scan())
led = Pin(0,Pin.OUT)
redes.connect("Wokwi-GUEST","")
while not redes.isconnected():
print(".", end="")
sleep(0.5)
print(redes.ifconfig())
def web_page():
html="""
<html>
<head>
</head>
<body>
<h1> HELLO, GUSTAS! </h1>
</body>
</html>
"""
return html
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('',80))
s.listen(5)
while True:
conn, addr = s.accept()
print('Conectado de %s' % str(addr))
request = conn.recv(1024)
request =str(request)
print(request)
resp = request.find("/on")
if resp > 0:
led.value(1)
resp = request.find("/off")
if resp > 0:
led.value(0)
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()
'''
led = Pin(0,Pin.OUT)
while True:
led.value(1)
sleep(1)
led.value(0)
sleep(1)
'''