from machine import Pin
import dht
import network
import urequests
import time
dht_sensor = dht.DHT22(Pin(14))
ssid = 'Wokwi-GUEST'
password = ''
google_script_url = 'https://script.google.com/macros/s/AKfycbxn60MAi3XM_gI4C8L3uQfv9ZBo5yliAVGLMG0uKf32VhUwu782uyvNLcdhjDRWFXUiLg/exec'
def connect_wifi():
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
while not wlan.isconnected():
pass
print('connected to WiFi')
def read_and_send_data():
try:
dht_sensor.measure()
temp = dht_sensor.temperature()
hum = dht_sensor.humidity()
url = google_script_url + '?temperature={}&humidity={}' .format(temp, hum)
response = urequests.get(url)
print(response.text)
response.close()
except OSError as e:
print('Failed to read sensor.')
def main():
connect_wifi()
while True:
read_and_send_data()
time.sleep(60)
main()