我有一个树莓派,我设法分离出独立工作的元素。继续以感应运动并拍摄照片,然后再通过Flask在我的本地网络上流式传输摄像机的数据。
但是,我希望它们能够同时运行,所以我一直在研究Flask Script模块和Manger功能。我相信我的安装程序正确。但是,当我运行“ runserver”命令时,实际上没有任何反应。
我想用Flask Script做什么吗?如果这是我的方法正确,还是有更好的解决方案。
谢谢
到目前为止,这是我的python脚本:
from importlib import import_module
import os
from flask_script import Server, Manager
from flask import Flask, render_template, Response
from camera import Camera
from gpiozero import MotionSensor
import time
# Code to take a snapshot when motion is detected
def senseMotion():
pir = MotionSensor(4)
while True:
if pir.motion_detected:
print('Motion detected')
Camera.snapshot()
time.sleep(60)
app = Flask(__name__)
manager = Manager(app)
# Flask app to view video stream in browser
@app.route('/')
def index():
"""Video streaming home page."""
return render_template('index.html')
def gen(camera):
"""Video streaming generator function."""
while True:
frame = camera.get_frame()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
@app.route('/video_feed')
def video_feed():
"""Video streaming route. Put this in the src attribute of an img tag."""
return Response(gen(Camera()),
mimetype='multipart/x-mixed-replace; boundary=frame')
@manager.command
def runserver():
senseMotion()
app.run(host='0.0.0.0', threaded=True)
if __name__ == "__main__":
manager.run()
#if __name__ == '__main__':
#app.run(host='0.0.0.0', threaded=True)