From dd3fce423ed7ad019b49bb2dad58467b9e8383c3 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sun, 11 Sep 2016 00:21:59 +0200 Subject: Use gevent to serve --- glutte_serial_web.py | 9 +++++++-- requirements.txt | 2 ++ serialrx.py | 2 +- static/style.css | 10 ++++++++++ templates/index.html | 23 +++++++++++++++++++++++ 5 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 static/style.css create mode 100644 templates/index.html diff --git a/glutte_serial_web.py b/glutte_serial_web.py index 2154599..bcb3261 100755 --- a/glutte_serial_web.py +++ b/glutte_serial_web.py @@ -22,6 +22,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +from gevent.wsgi import WSGIServer from time import sleep from flask import Flask, render_template import serialrx @@ -32,6 +33,10 @@ ser = serialrx.SerialRX() @app.route('/') def index(): + return render_template('index.html') + +@app.route('/stream') +def stream(): def generate(): while True: line = ser.get_line() @@ -41,10 +46,10 @@ def index(): return app.response_class(generate(), mimetype='text/plain') - try: ser.start() - app.run() + http_server = WSGIServer(('', 5000), app) + http_server.serve_forever() except KeyboardInterrupt: print("Ctrl-C received, quitting") finally: diff --git a/requirements.txt b/requirements.txt index ecc337d..84f7820 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,7 @@ click==6.6 Flask==0.11.1 +gevent==1.1.2 +greenlet==0.4.10 itsdangerous==0.24 Jinja2==2.8 MarkupSafe==0.23 diff --git a/serialrx.py b/serialrx.py index f4510da..66de50b 100644 --- a/serialrx.py +++ b/serialrx.py @@ -29,7 +29,7 @@ import collections SERIALPORT="/dev/ttyACM0" BAUDRATE=9600 -LINES_TO_KEEP=2000 +LINES_TO_KEEP=200 class SerialRX(threading.Thread): def __init__(self): diff --git a/static/style.css b/static/style.css new file mode 100644 index 0000000..1a595e6 --- /dev/null +++ b/static/style.css @@ -0,0 +1,10 @@ +body { + font-family: "Lucida Sans Unicode","Lucida Grande",Sans-Serif; + color: #3E3E3E; + font-size: 12px; +} + +p { + padding: 5px; +} + diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..1b68ce2 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,23 @@ + + + + + Moniteur de Glutte + + + +

Ceci n'est pas une Glutte

+

+
+
-- 
cgit v1.2.3