import network import socket from machine import Pin, I2C from time import sleep import ssd1306 # --- WiFi konfiguracja --- SSID = "iPhone (Mikolaj)" PASSWORD = "Techniczna1" print("Łączenie z WiFi...") sta = network.WLAN(network.STA_IF) sta.active(True) sta.connect(SSID, PASSWORD) while not sta.isconnected(): sleep(0.2) print("Połączono!") print("Adres IP:", sta.ifconfig()[0]) # --- OLED --- i2c = I2C(scl=Pin(5), sda=Pin(4)) # D1, D2 oled = ssd1306.SSD1306_I2C(128, 64, i2c) # startowa wartość value = 0 # --- serwer www --- addr = socket.getaddrinfo("0.0.0.0", 80)[0][-1] s = socket.socket() s.bind(addr) s.listen(1) print("Serwer działa -> wpisz w przeglądarce:") print("http://{}/".format(sta.ifconfig()[0])) while True: cl, addr = s.accept() request = cl.recv(1024).decode() if "value=" in request: try: part = request.split("value=")[1] num = int(part.split(" ")[0]) if 0 <= num <= 100: value = num except: pass # OLED wyświetlanie oled.fill(0) oled.text("Wartosc:",0,0) oled.text(str(value),0,16) oled.show() html = """
Aktualna wartosc: """ + str(value) + """
""" cl.send("HTTP/1.1 200 OK\r\n") cl.send("Content-Type: text/html\r\n\r\n") cl.send(html) cl.close()