我目前正在使用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')
当运动传感器检测到运动时,执行回调函数“alert”:
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秒后,服务器关闭。你有什么建议吗?你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐