aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2016-09-11 00:21:59 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2016-09-11 00:21:59 +0200
commitdd3fce423ed7ad019b49bb2dad58467b9e8383c3 (patch)
tree9dfce7b3435f6e88493c0dd4eac9a69281217a5b
parent1599d900a498f7575b47b3dbfe8d52613cbe3f50 (diff)
downloadglutte-serial-web-dd3fce423ed7ad019b49bb2dad58467b9e8383c3.tar.gz
glutte-serial-web-dd3fce423ed7ad019b49bb2dad58467b9e8383c3.tar.bz2
glutte-serial-web-dd3fce423ed7ad019b49bb2dad58467b9e8383c3.zip
Use gevent to serve
-rwxr-xr-xglutte_serial_web.py9
-rw-r--r--requirements.txt2
-rw-r--r--serialrx.py2
-rw-r--r--static/style.css10
-rw-r--r--templates/index.html23
5 files changed, 43 insertions, 3 deletions
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 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+ <title>Moniteur de Glutte</title>
+ <link rel="stylesheet" href="static/style.css" type="text/css" media="screen" charset="utf-8"/>
+ </head>
+<body>
+ <h1>Ceci n'est pas une Glutte</h1>
+<pre id="output"></pre>
+<script>
+ var output = document.getElementById('output');
+
+ var xhr = new XMLHttpRequest();
+ xhr.open('GET', '{{ url_for('stream') }}');
+ xhr.send();
+
+ setInterval(function() {
+ output.textContent = xhr.responseText;
+ window.scrollTo(0, document.body.scrollHeight);
+ }, 1000);
+</script>
+</body></html>