2017-08-15 4 views
1

私は自分のRaspberry Pi用のストリーミングサーバーを持っています。私は、ウェブサイトからサーボ(パンとチルト)でコントロールできるようにしたい。したがって、ページを更新せずに、bottonがWebサイトで押されたときに起動するpythonスクリプトを開始したいと考えています。それを行う方法はありますか?私はフラスコを使用しています。ページを更新せずにRaspberry Piへのスクリプトを開始

+0

私はあなたが答えてくれてありがとうPythonの – estrella1995

答えて

0

あなたのような設定にごフラスコアプリでエンドポイントを望む:

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>

+0

を使用することをmensionし忘れました! 'app.send_static_file'を使うと「見つかりません」というメッセージが表示されます。 app.route @ リターンrender_template( 'index.htmlを') ( '/アップ/')\t DEFアップ: – estrella1995

+0

'@のapp.route( '/') DEFインデックス():このような私のコードを見て(): \t control.up() \t戻りrender_template( 'のindex.html') \t DEF GEN(カメラ): 一方TRUE: フレーム= camera.get_frame() 収率(B ' - フレーム\ r \ n ' b'コンテンツタイプ:画像/ jpeg \ r \ n \ r \ n '+フレーム+ b' \ r \ n ') @ app.rmimetype = 'multipart/x-mixed-replace;返信応答(gen(Camera) (host = '0.0.0.0'、threaded = True) ' if __name__ == '__main__': app.run – estrella1995

関連する問題