from machine import Pin
import network
import dht
import time
import urequests
sta= network.WLAN(network.STA_IF)
sta.active(True)
sta.connect('seanwee','17485523')
print('Linking...')
while not sta.isconnected():
pass
print('Link OK')
p0=Pin(21, Pin.IN)
d=dht.DHT22(p0)
make_url= 'https://hook.eu2.make.com/8rvc3mlbow7yb7sv9raiins3xykoah7p'
j=0
while True:
f=open('DHT_temp.txt','w')
Temp=0
Hum=0
try:
for i in range(5):
d.measure()
t=d.temperature()
h=d.humidity()
Temp+=t
Hum+=h
time.sleep(0.5)
except Exception as e: print(e)
Temp = Temp/5
Hum = Hum/5
print('Temperature=', Temp, 'C', ',Humidity=', Hum, '%')
if(Temp>=55):
try:
print(make_url+"DHT_temp ="+str(Temp))
res=urequests.post(make_url+'DHT_temp ='+str(Temp))
res.close()
print("溫度過高,目前為 "+str(Temp)+"度")
except Exception as e: print(e)
j=j+1
print('第'+str(j)+'筆'+'publish finish')
f.write(str(Temp)+' '+str('Hum')+'\n')
time.sleep(5)
f.close()