【问题标题】:Start a script to Raspberry Pi without refresh the page在不刷新页面的情况下启动 Raspberry Pi 脚本
【发布时间】:2017-08-15 12:08:46
【问题描述】:

我的 Raspberry Pi 有一个流媒体服务器。我希望能够通过网站上的伺服系统(平移和倾斜)来控制它。因此,我想启动一个 python 脚本,当在网站上按下一个按钮时启动,而不刷新页面。有没有办法做到这一点?我正在使用烧瓶。

【问题讨论】:

  • 忘了说我用的是 Python

标签: html css flask raspberry-pi raspberry-pi3


【解决方案1】:

您可能希望在您的烧瓶应用程序中设置一个端点,例如:

from flask import Flask
app = Flask(__name__)

@app.route("/")
def indexpage():
    # Serve your index web page here
    return app.send_static_file('index.html')

@app.route("/runscript")
def runscript():
    # Do whatever you want here
    run_my_script()

app.run()

然后在您的网页中有一个表单,该表单在 runscript 端点向您的应用发送 GET 请求。

<form action="/runscript" method="get">
  <input type="submit" value="Submit">
</form>

【讨论】:

  • 感谢您的回答!当我使用app.send_static_file 时,我得到“未找到”。我的代码如下所示:
  • @app.route('/') def index(): return render_template('index.html') @app.route('/up/') def up(): control.up() return render_template('index.html') def gen(camera): 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(): return Response(gen(Camera()), mimetype='multipart/x-mixed-replace; boundary=frame') if __name__ == '__main__': app.run(host='0.0.0.0', threaded=True)
猜你喜欢
  • 2017-05-11
  • 2015-08-11
  • 1970-01-01
  • 2017-03-24
  • 2022-07-23
  • 2023-04-01
  • 2019-11-25
  • 2017-12-21
  • 1970-01-01
相关资源
最近更新 更多