import network import time import socket from machine import Pin def web_page(ip_address, LED): f = open("33_Button.html") #f = open("33_Hyperlink.html") x = f.read() x = x.replace('\r\n',' ') x = x.replace('aaaaa',ip_address) x = x.replace('bbbbb', str(LED)) return(x) ssid = 'Pico-Network' password = 'PASSWORD' LED = Pin(16, Pin.OUT) OnOff = ['OFF', 'ON'] ap = network.WLAN(network.AP_IF) ap.config(ssid=ssid, password=password) ap.active(True) while ap.active() == False: pass print('AP Mode Is Active, You can Now Connect') IP_Address = ap.ifconfig()[0] print('IP Address To Connect to:: ' + IP_Address) #print('IP Address To Connect to:: ' + ap.ifconfig()[0]) print('Channel', ap.config('channel')) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(('', 80)) s.listen(5) LED.value(0) while(1): flag = 0 while(flag == 0): conn, addr = s.accept() request = conn.recv(1024) request = request.decode('utf-8') if(request.find('favicon') > 0): flag = 1 else: response = web_page(IP_Address, OnOff[LED.value()] ) conn.send(response) conn.close() n = request.find('Referer:')+9 request = request[n:] n = request.find('\r\n') request = request[0:n] for i in range(0,10): n = request.find('/')+1 if(n>0): request = request[n:] print(request) if(request == 'light_on'): LED.value(1) if(request == 'light_off'): LED.value(0) response = web_page(IP_Address, LED.value() ) conn.send(response) conn.close()