-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
63 lines (45 loc) · 1.56 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import sys
import time
import redis
from flask import Flask, render_template, Response, send_from_directory
from flask_assets import Environment, Bundle
# import function to start reading/writing from serial port
import arduinoPoller
red = redis.StrictRedis()
def create_app():
# use error as stdout
sys.stdout = sys.stderr
# create Flask application
app = Flask(__name__)
# render SCSS
scss = Bundle('site.scss', filters='libsass', output='site.css')
assets = Environment(app)
assets.url = app.static_url_path
assets.register('scss_all', scss)
# Spin up polling thread
arduinoPoller.setupArduinoPolling(0.333)
# route to favicon
@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'static'), 'favicon.ico')
@app.route('/')
def home():
"""Page: home of site"""
return render_template('index.html')
@app.route("/stream/console")
def console_stream():
"""Stream: continuous pipeline stream
This stream is connected to by client via Javascript to constantly download messages (Responses) from the server.
See ./templates/index.html for Javascript code.
"""
def events():
while True:
yield red.get('msg')
arduinoPoller.keepPollAlive()
time.sleep(.1)
return Response(events(), mimetype='text/plain')
return app
if __name__ == '__main__':
from waitress import serve
serve(create_app(), host='0.0.0.0', port='80')