import network, time, urequests
from machine import ADC, Pin
WIFI_SSID = 'Wokwi-GUEST'
WIFI_PASS = ''
photoPIN = 34
webhook_url = "https://maker.ifttt.com/trigger/ESP32/with/key/bRFry-_5L3zhvGJEezbG7"
def readLight(photoGP):
photoRes = ADC(Pin(photoGP))
light = photoRes.read()
light = round(light/65535*100,2)
return light
print("Conectant a la WiFi", end="")
wifi = network.WLAN(network.STA_IF)
wifi.active(True)
wifi.connect(WIFI_SSID, WIFI_PASS)
while not wifi.isconnected():
print(".", end="")
time.sleep(0.1)
print(" Conectat!")
while True:
print("light: " + str(readLight(photoPIN)) +"%")
time.sleep(5) # set a delay between readings
url = webhook_url + "?value1=" + str(readLight(photoPIN))
resposta = urequests.get(url)
print(resposta.text)
print (resposta.status_code)
resposta.close ()