1

I have a streaming server for my Raspberry Pi. I want to be able to control it with servos (pan and tilt) from the website. Therefore I want to start a python script, that starts when a botton is pressed at the website, without refreshing the page. Is there a way to do that? I'm using flask.

1 Answers1

0

You would want to setup an endpoint in your flask app like:

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()

Then in your webpage have a form which sends a GET request to your app at the runscript endpoint.

<form action="/runscript" method="get">
  <input type="submit" value="Submit">
</form>
Benjamin Gorman
  • 360
  • 1
  • 11
  • Thank you for you answer! When I use `app.send_static_file` I get "Not found". My code look like this: – estrella1995 Aug 15 '17 at 13:05
  • `@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)` – estrella1995 Aug 15 '17 at 13:08