import network import urequests import time from machine import Pin # Wi-Fi Credentials ssid = "iPhone SM" # Wi-Fi SSID password = "lalalala" # Wi-Fi password # ssid = "Aluminum_Flat" # Wi-Fi SSID # password = "HowLargeAreYourHands" # Wi-Fi password # Connect to Wi-Fi wlan = network.WLAN(network.STA_IF) wlan.active(True) wlan.connect(ssid, password) print("Connecting to WiFi...") while not wlan.isconnected(): time.sleep(1) print("Connected! IP:", wlan.ifconfig()) # Configure onboard LED led = Pin("LED", Pin.OUT) # URL of the Flask app signal_url = "https://Sergio.pythonanywhere.com/" while True: try: # Fetch the HTML content from the Flask app response = urequests.get(signal_url) html_content = response.text response.close() # Extract the LED state from the HTML start_marker = "Current LED State: " end_marker = "" start = html_content.find(start_marker) + len(start_marker) end = html_content.find(end_marker, start) led_state = html_content[start:end].strip() print("Parsed LED State:", led_state) # Act on the LED state if led_state == "On": led.on() elif led_state == "Off": led.off() else: print("Unknown LED state:", led_state) except Exception as e: print("Error fetching or parsing command:", e) # Poll every x time.sleep(0.1)