import time
import network
import BlynkLib
from machine import Pin
led=Pin(16, Pin.OUT)
led1=Pin(18,Pin.OUT)
wlan = network.WLAN()
wlan.active(True)
wlan.connect("Ash","12345678")
BLYNK_AUTH = 'Z1eZ6BFkwwxg9f-RwxwJYVE66_Zo_N4B'
# connect the network
wait = 10
while wait > 0:
if wlan.status() < 0 or wlan.status() >= 3:
break
wait -= 1
print('waiting for connection...')
time.sleep(1)
# Handle connection error
if wlan.status() != 3:
raise RuntimeError('network connection failed')
else:
print('connected')
ip=wlan.ifconfig()[0]
print('IP: ', ip)
#"Connection to Blynk"
# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)
# Register virtual pin handler
@blynk.on("V0") #virtual pin V0
def v0_write_handler(value): #read the value
if int(value[0]) == 1:
led.value(1) #turn the led on
else:
led.value(0) #turn the led off
@blynk.on("V2") #virtual pin V0
def v2_write_handler(value): #read the value
if int(value[0]) == 1:
led1.value(1) #turn the led on
else:
led1.value(0)
while True:
blynk.run()