working server for streaming temperature data

master
James Gao 2014-10-20 03:35:01 +00:00
rodzic e53b70f4c5
commit ea40bee4af
2 zmienionych plików z 16 dodań i 13 usunięć

Wyświetl plik

@ -29,8 +29,8 @@ class WebApp(object):
def __init__(self, monitor, port=8888):
self.handlers = [
(r"/ws/", ClientSocket, dict(parent=self)),
(r"/data.json", DataRequest, dict(monitor=monitor)),
(r"/(.*)", tornado.web.StaticFileHandler, dict(path=cwd)),
(r"^/data.txt$", DataRequest, dict(monitor=monitor))
]
self.sockets = []
self.port = port
@ -38,7 +38,7 @@ class WebApp(object):
def send(self, data):
jsondat = json.dumps(data)
for sock in self.sockets:
socket.write_message(jsondat)
sock.write_message(jsondat)
def run(self):
self.app = tornado.web.Application(self.handlers, gzip=True)
@ -46,12 +46,15 @@ class WebApp(object):
tornado.ioloop.IOLoop.instance().start()
if __name__ == "__main__":
import thermo
monitor = thermo.Monitor()
try:
import thermo
monitor = thermo.Monitor()
app = WebApp(monitor)
def send_temp(time, temp):
app.send(dict(time=time, temp=temp))
monitor.callback = send_temp
monitor.start()
app.run()
app = WebApp(monitor)
def send_temp(time, temp):
app.send(dict(time=time, temp=temp))
monitor.callback = send_temp
monitor.start()
app.run()
except KeyboardInterrupt:
monitor.stop()

Wyświetl plik

@ -83,8 +83,8 @@ var tempgraph = (function(module) {
sock.onmessage = function(event) {
var data = JSON.parse(event.data);
this.update_temp(data);
}
*/
}.bind(this);
$("#temp_scale_C").click(function() { this.setScale("C");}.bind(this));
$("#temp_scale_F").click(function() { this.setScale("F");}.bind(this));
//$("#temp_scale_C").click(function() { this.setScale("C");}.bind(this));
@ -102,7 +102,7 @@ var tempgraph = (function(module) {
return module;
}(tempgraph || {}));
d3.tsv("data.txt", function(error, data) {
d3.json("data.json", function(error, data) {
var newdata = [], d;
for (var i = 0; i < data.length; i+=4) {
d = data[i];