kopia lustrzana https://github.com/jamesgao/kiln_controller
Forgot to actually activate the websocket
rodzic
5b76136508
commit
e53b70f4c5
|
@ -17,11 +17,20 @@ class ClientSocket(websocket.WebSocketHandler):
|
|||
def on_close(self):
|
||||
self.parent.sockets.remove(self)
|
||||
|
||||
class DataRequest(tornado.web.RequestHandler):
|
||||
def initialize(self, monitor):
|
||||
self.monitor = monitor
|
||||
|
||||
def get(self):
|
||||
output = [dict(time=ts[0], temp=ts[1]) for ts in self.monitor.history]
|
||||
self.write(json.dumps(output))
|
||||
|
||||
class WebApp(object):
|
||||
def __init__(self, handlers, port=8888):
|
||||
def __init__(self, monitor, port=8888):
|
||||
self.handlers = [
|
||||
(r"/ws/", ClientSocket, dict(parent=self)),
|
||||
(r"/(.*)", tornado.web.StaticFileHandler, dict(path=cwd)),
|
||||
(r"^/data.txt$", DataRequest, dict(monitor=monitor))
|
||||
]
|
||||
self.sockets = []
|
||||
self.port = port
|
||||
|
@ -40,7 +49,7 @@ if __name__ == "__main__":
|
|||
import thermo
|
||||
monitor = thermo.Monitor()
|
||||
|
||||
app = WebApp([])
|
||||
app = WebApp(monitor)
|
||||
def send_temp(time, temp):
|
||||
app.send(dict(time=time, temp=temp))
|
||||
monitor.callback = send_temp
|
||||
|
|
|
@ -78,13 +78,11 @@ var tempgraph = (function(module) {
|
|||
return {x:d.x, y:this.scalefunc(d.y)};
|
||||
}
|
||||
module.Monitor.prototype._bindUI = function() {
|
||||
/*
|
||||
var sock = new WebSocket("ws://localhost/socket/", "protocolOne");
|
||||
|
||||
var sock = new WebSocket("ws://"+window.location.hostname+":"+window.location.port+"/ws/", "protocolOne");
|
||||
|
||||
sock.onmessage = function(event) {
|
||||
var data = JSON.parse(event.data);
|
||||
this.update(data);
|
||||
this.update_temp(data);
|
||||
}
|
||||
*/
|
||||
$("#temp_scale_C").click(function() { this.setScale("C");}.bind(this));
|
||||
|
|
Ładowanie…
Reference in New Issue