import network import socket from machine import ADC, Pin import time # --- WLAN-Konfiguration --- WIFI_SSID = "ROUTER2" WIFI_PASS = "h347THuie894UIERIF83hrUJ4aspyq80734Y" # --- Statische IP --- STATIC_IP = "192.168.168.248" NETMASK = "255.255.255.0" GATEWAY = "192.168.168.1" DNS = "192.168.168.1" # --- Sensor --- sensor = ADC(Pin(2)) RAW_TROCKEN = 4095 RAW_NASS = 750 SPAN = RAW_TROCKEN - RAW_NASS def read_percent(): raw = sensor.read() raw = min(max(raw, RAW_NASS), RAW_TROCKEN) percent = (RAW_TROCKEN - raw) / SPAN * 100 return raw, percent # --- LEDs --- leds = { 1: Pin(7, Pin.OUT), 2: Pin(21, Pin.OUT), 3: Pin(4, Pin.OUT), 4: Pin(10, Pin.OUT), 5: Pin(9, Pin.OUT), 6: Pin(5, Pin.OUT), 7: Pin(20, Pin.OUT), 8: Pin(8, Pin.OUT), 9: Pin(6, Pin.OUT) } gnd_leds = {1, 2, 9} vcc_leds = {3, 4, 5, 6, 7, 8} def leds_all_off(): for num, pin in leds.items(): pin.value(0 if num in gnd_leds else 1) def led_on(num): leds[num].value(1 if num in gnd_leds else 0) # --- Button --- button = Pin(3, Pin.IN, Pin.PULL_UP) # --- Zentrale Messroutine --- def measure_and_update(): raw, percent = read_percent() leds_all_off() num_leds_on = int(percent // 10) + 1 num_leds_on = max(1, min(9, num_leds_on)) for i in range(1, num_leds_on + 1): led_on(i) time.sleep(1) leds_all_off() return raw, percent # --- WLAN verbinden --- wlan = network.WLAN(network.STA_IF) wlan.active(True) wlan.ifconfig((STATIC_IP, NETMASK, GATEWAY, DNS)) wlan.connect(WIFI_SSID, WIFI_PASS) print("Verbinde mit WLAN...") while not wlan.isconnected(): time.sleep(0.2) print("WLAN verbunden:", wlan.ifconfig()) # --- HTML-Seite --- def webpage(raw, percent): return f"""