Switch from socket.io to REST for cadence streaming in attempt to fix timeout issue
This commit is contained in:
28
app.py
28
app.py
@@ -3,7 +3,7 @@ import json
|
||||
from urllib import response
|
||||
from dateutil.relativedelta import relativedelta
|
||||
import os
|
||||
from flask import Flask, render_template
|
||||
from flask import Flask, render_template, request
|
||||
import jinja_partials
|
||||
from flask_htmx import HTMX
|
||||
import minify_html
|
||||
@@ -18,7 +18,7 @@ app = Flask(__name__)
|
||||
app.config['SECRET_KEY'] = 'secret!'
|
||||
jinja_partials.register_extensions(app)
|
||||
htmx = HTMX(app)
|
||||
socketio = SocketIO(app, cors_allowed_origins='*')
|
||||
#socketio = SocketIO(app, cors_allowed_origins='*')
|
||||
db = DataBase(app)
|
||||
|
||||
|
||||
@@ -37,12 +37,12 @@ def response_minify(response):
|
||||
return response
|
||||
|
||||
|
||||
@socketio.on('message')
|
||||
def handle_message(data):
|
||||
current_time = datetime.now().replace(
|
||||
microsecond=0).isoformat()
|
||||
print('' + current_time + ' ' + json.dumps(data))
|
||||
db.insert_cadence(data['rpm'], data['id'])
|
||||
# @socketio.on('message')
|
||||
# def handle_message(data):
|
||||
# current_time = datetime.now().replace(
|
||||
# microsecond=0).isoformat()
|
||||
# print('' + current_time + ' ' + json.dumps(data))
|
||||
# db.insert_cadence(data['rpm'], data['id'])
|
||||
|
||||
|
||||
@ app.route("/")
|
||||
@@ -73,7 +73,17 @@ def overview(device_id):
|
||||
return render_template('overview.html', last_cadence=last_cadence, cadences=cadences[-15:], graph_data=graph_data)
|
||||
|
||||
|
||||
@ app.route("/cadence", methods=['POST'])
|
||||
def cadence():
|
||||
data = request.get_json()
|
||||
print('' + datetime.now().replace(microsecond=0).isoformat() +
|
||||
' ' + json.dumps(data))
|
||||
db.insert_cadence(data['rpm'], data['id'])
|
||||
return 'ok'
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Bind to PORT if defined, otherwise default to 5000.
|
||||
port = int(os.environ.get('PORT', 5000))
|
||||
socketio.run(app, host='127.0.0.1', port=port)
|
||||
#socketio.run(app, host='127.0.0.1', port=port)
|
||||
app.run(host='127.0.0.1', port=port)
|
||||
|
||||
Reference in New Issue
Block a user