-
-
Save kelvinninja1/b67947ad6bf6ff934c93c7614d95a148 to your computer and use it in GitHub Desktop.
Revisions
-
otomura created this gist
Oct 24, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ import flask import serial app = flask.Flask(__name__) arduino_serial = serial.Serial('/dev/ttyACM0', 9600) def event_stream(): while True: yield "data: " + arduino_serial.readline() + "\n\n" @app.route('/stream') def stream(): return flask.Response(event_stream(), mimetype="text/event-stream") @app.route('/') def index(): return """ <!doctype html> <title>Arduino serial monitor</title> <div id="data"/> <script> (function(){ var source = new EventSource('/stream'); var data = document.getElementById('data'); source.onmessage = function(e) { data.innerHTML = e.data + '<br/>' + data.innerHTML; }; })(); </script> """ if __name__ == '__main__': app.run(debug = True)