import network
import time
from machine import Pin
import BlynkLib
# Wi-Fi credentials
WIFI_SSID = 'Wokwi-GEUST'
WIFI_PASSWORD = ''
# Blynk authentication token
BLYNK_AUTH = "ZA6mYlfqoZIJZWMopjPql0BezFMU4C3D"
# LED pin (modify for Wokwi GPIO setup)
LED_PIN = 2 # GPIO2, usually built-in on ESP32
# Initialize LED
led = Pin(LED_PIN, Pin.OUT)
# Connect to Wi-Fi
def connect_wifi():
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(WIFI_SSID, WIFI_PASSWORD)
print("Connecting to Wi-Fi...")
while not wlan.isconnected():
time.sleep(1)
print(".")
print("Wi-Fi connected:", wlan.ifconfig())
# Blynk setup
blynk = BlynkLib.Blynk(BLYNK_AUTH)
# Blynk virtual pin handler for LED control
@blynk.on("V1") # Replace V1 with the virtual pin you configure in the Blynk app
def v1_write_handler(value):
if int(value[0]) == 1:
led.value(1) # Turn LED on
print("LED ON")
else:
led.value(0) # Turn LED off
print("LED OFF")
# Main program
def main():
connect_wifi()
print("Starting Blynk...")
while True:
blynk.run()
time.sleep(0.1)
if __name__ == "__main__":
main()