https://github.com/tiasimoneriley/pulse
So i am trying to make this code run to get the pulses, however the connection to Websocket is immediatly closed and I don't understand why.
It closing right away is not letting the frames of the video get computed to get the pulses.
Also, I am new to this whole thing so if anyone can figure it out please tell me whats wrong.
Thank you.
This is what my console shows
websocket open! websocket.js:5
closed websocket.js:22
T1 camera.js:70
T2 camera.js:76
T3 camera.js:82
T4 camera.js:84
T5 camera.js:86
begin startCapture() camera.js:397
T6 camera.js:88
WebSocket is already in CLOSING or CLOSED state. websocket.js:18
WebSocket is already in CLOSING or CLOSED state. websocket.js:18
Here is the app.py
import json
import os
from flask import Flask, render_template
from flask_sockets import Sockets
import model
app = Flask(__name__)
sockets = Sockets(app)
@app.route("/")
def index():
return render_template("splash.html")
@app.route("/begin")
def get_heartrate():
return render_template("index.html")
@sockets.route('/echo')
def echo_socket(ws):
while True:
message = json.loads(ws.receive())
signals = model.parse_RGB(message)
ws.send(signals)
if __name__ == "__main__":
from gevent import pywsgi
from geventwebsocket.handler import WebSocketHandler
port = int(os.environ.get('PORT', 5000))
print("Hosting on port {}".format(port))
server = pywsgi.WSGIServer(('', port), app, handler_class=WebSocketHandler)
server.serve_forever()
and this is the websocket.js
var dataSocket = new WebSocket(location.protocol.replace("http", "ws") + location.host + "/echo");
dataSocket.onopen = function(){
console.log("websocket open!");
console.log(dataSocket);
}
dataSocket.onmessage = function(e){
var data = JSON.parse(e.data);
if (data.id === "ICA"){
camera.cardiac(data.array, data.bufferWindow);
}
}
function sendData(data){
dataSocket.send(data);
}
dataSocket.onclose = function(){
console.log('closed');
}