from micropyserver import MicroPyServer import time from machine import Pin, PWM import network import gc _init() gc.collect() LedR = PWM(Pin(13, Pin.OUT)) LedG = PWM(Pin(14, Pin.OUT)) LedB = PWM(Pin(15, Pin.OUT)) wlan_id = "Wi-Fi_Name" wlan_pass = "Wi-Fi_Password" wlan = network.WLAN(network.STA_IF) wlan.active(True) wlan.connect(wlan_id, wlan_pass) time.sleep(2) while wlan.isconnected() == False: pass print('Device IP:', wlan.ifconfig()[0]) def index(request, params): html_color = '4AD686' if ('color' in params): html_color = params['color'][3:9] print(html_color) r = html_color[0:2] g = html_color[2:4] b = html_color[4:6] r = int(r, 16) g = int(g, 16) b = int(b, 16) r = int(r * 1023 / 255) g = int(g * 1023 / 255) b = int(b * 1023 / 255) LedR.duty(1023-r) LedG.duty(1023-g) LedB.duty(1023-b) html_file = open("color.html") html = html_file.read() html = html.replace('<=VALUE=>', '#' + html_color) html_file.close() server.send(html, content_type="Content-Type: text/html") LedR.duty(0) LedG.duty(0) LedB.duty(0) server = MicroPyServer() server.add_route("/", index) server.start()