Question: CODE 2 from machine import Pin from time import sleep import network import socket led = Pin ( 1 6 , Pin.OUT ) m y

CODE 2
from machine import Pin from time import sleep import network import socket led =
Pin(16, Pin.OUT)my Pin = Pin(16, Pin.OUT) ssid = "CCSU-SOT-Lab" password =
"AlH@C3ntral!" def connect(): wlan = network.WLAN(network.STA_IF)
wlan.active(True) wlan.connect(ssid, password) while wlan.isconnected()== False:
print('Waiting for connection...') sleep(1) ip = wlan.ifconfig print (fConnected on {:{ip}')
return ip def open_socket(ip): # Open a socket address =(ip,80) connection =
socket.socket() connection. bind(address) connection. listen(1) return connection def
webpage(state): #Template HTML html = f
action=".ighton">>=====LED is
{state} p > bodys html>>""" return str(html) def serve(connection): #Start a web
server state = 'OFF' led.off() while True: client = connection.accept()[0] request =
client.recv(1024) request = str(request) try: request = request.split()[1] except
IndexError: pass if request == 'lighton?': led.value(1) state ='ON' elif request
== 'hightoff?': led.value(0) state = 'OFF' html = webpage(state) client.send(html)
client.close() try: ip=connect() print(ip) connection = open_socket(ip) print(connection)
state ='ON' html=webpage(state) print(( html) serve(connection)
except KeyboardInterrupt: machine.reset()
CODE 2 from machine import Pin from time import

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!