import network
import unrequests
impoent time
import dth
from machine import pin
- WIFI SSID = "wokwi- GUEST"
WIFI-PASS= "
THINGSPEAK API -KEY = "GGXRAC4QTU6TRJXB"
THINGSPEAK-URI-"https://thingspeak.com/update"
dth-sensor=dth.DHT22(pin (15))
print("connecting to wifi....")
Wlan=network-WLAN (network.STA-IF)
Wlan.active(True)
wlan.connect (WIFI-SSID,WIFI-PASS)
while not wlan is connected();
time.sleep (0.5)
print(".",end="")
print ("\n connected to WIFI")
while true:
try;
dht-sensor.measure()
temp = dht-sensor.temperature()
hum = dht-sensor.humidity()
print ("Temperature;",temp,"°C)-Humidity:"hum,"%")
response=urequests.get(t"(THINGSPEAK_URL)?api_key=(THINGSPEAK_API_KEY)& field 1=(temp)&field 2=(hum)")
print("Thingspeak response :",response.text)
response.close()
except Exception as e:
print("Error:",e)
time,sleep(15)