Code: Select all
def handle_interrupt(pin):
global motion
motion = True
global interrupt_pin
interrupt_pin = pin
pir.irq(trigger=Pin.IRQ_RISING, handler=handle_interrupt)
UPDATE_TIME_INTERVAL = 600000 # in ms
last_update = time.ticks_ms()
motion = 0
while True:
if time.ticks_ms() - last_update >= UPDATE_TIME_INTERVAL:
dht1.measure()
temp=dht1.temperature
hum=dht1.humidity
request = urequests.get( 'https://api.asksensors.com/write/'+'APIkey'+'module1='+str(dht_temp)+'&module2='++str(hum))
request.close()
last_update = time.ticks_ms()
elif motion:
print('motion detected')
motion_start= time.ticks_ms()
motion_time = 1000
motion = 1
request = urequests.get( 'https://api.asksensors.com/write/'+'APIkey'+'module3='+str(motion))
request.close()
if time.ticks_ms() - motion_start >= motion_time:
motion = 0
request = urequests.get( 'https://api.asksensors.com/write/'+'APIkey'+'module3='+str(motion))
request.close()