모션센서 사용 질문(timer사용 관련)
조회수 755회
2초마다 count 값을 1씩 증가시켜서 count값이 4이상이 되면 스마트폰에 푸시알람이 오게하는 코드입니다. 문제는 count값이 푸시알람이 울려야만 초기화 된다는 점인데, 10초이상 감지가 안되면 count값을 초기화하는 방법이 있을까요?
import RPi.GPIO as GPIO
import time
import json
import requests
headers = {
'Authorization': 'my_key',
'Content-Type': 'application/json',
}
data = {
'to': '/topics/bell',
'data': {
'title': '외부인 접근 알림',
'body': 'SMART DOOR SYSTEM',
}
}
GPIO.setmode(GPIO.BCM)
pirPin = 26
GPIO.setup(pirPin, GPIO.IN)
count=0
def MotionSensor(pirPin):
global count
if count >= 4 :
print ("Motion Detected!")
response = requests.post('https://fcm.googleapis.com/fcm/send', headers=headers, data=json.dumps(data))
print (response)
count = 0
else:
count += 1
print ("count = %d" % count)
time.sleep(2)
print("Motion Sensor Alarm")
time.sleep(1)
print("Ready")
try:
GPIO.add_event_detect(pirPin, GPIO.RISING, callback=MotionSensor)
while 1:
time.sleep(1)
except KeyboardInterrupt:
print("Quit")
GPIO.cleanup()
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력