我目前正在使用Python(Flask)和Raspberry开发警报系统。
我的首页只有一个按钮:“ ARM”重定向到“ / ARM”,页面“ / DISARM”:
@app.route('/ARM')
def ARM():
GPIO.remove_event_detect(sensor)
# Blue LED on
GPIO.output(blue,1)
# detection based on motion sensor
GPIO.add_event_detect(sensor, GPIO.RISING, callback=alert)
# The template with "DISARM" button
return render_template('home_disarm.html')
@app.route('/DISARM')
def DISARM():
GPIO.remove_event_detect(sensor)
# blue LED off / red LED off / buzzer off
GPIO.output(blue,0)
GPIO.output(red,0)
GPIO.output(buzz,0)
# the template with "ARM" button
return render_template('home.html')
运动传感器检测到运动时,将执行回调函数“警报”:
def alert(sensor):
GPIO.remove_event_detect(sensor)
# Blue LED off / Red LED on / Buzzer on
GPIO.output(blue,0)
GPIO.output(red,1)
GPIO.output(buzz,1)
# wait 20s for automatic disarming
sleep(20)
GPIO.output(blue,1)
GPIO.output(red,0)
GPIO.output(buzz,0)
# arm again
GPIO.add_event_detect(sensor, GPIO.RISING, callback=int)
当系统布防(但未触发)时,可以将其撤防,但是问题在于在检测到之后(20秒周期)停用系统。当我尝试在此期间撤防时,它可以工作一段时间,但是20秒钟后服务器已关闭。你有什么建议吗?