From cd2065dd4e451f68548e2576cb92c4201d7b9121 Mon Sep 17 00:00:00 2001 From: chrono Date: Sat, 23 Nov 2013 22:10:51 +0000 Subject: [PATCH] Fixes to picoreflowd and change to localhost in index.html --- .gitignore | 7 +++++++ README.md | 7 +++++++ picoreflowd.py | 38 ++++++++++++++++++++------------------ public/index.html | 4 ++-- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 0d20b64..8e01749 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,8 @@ *.pyc +*~ +\#* +.#* +*.swp +.DStore/ +thumbs.db + diff --git a/README.md b/README.md index 501b390..c73b4c3 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,10 @@ picoReflow Turns a Raspberry Pi into a universal, web enabled Reflow Oven Controller. Based on MAX 31855 Cold-Junction K-Type Thermocouple and Raspberry Pi GPIO driven Solid State Relays. + + +Python Requirements: + + - dev-python/bottle + - dev-python/gevent + - dev-python/gevent-websocket diff --git a/picoreflowd.py b/picoreflowd.py index 4463c04..a9828f1 100644 --- a/picoreflowd.py +++ b/picoreflowd.py @@ -12,24 +12,37 @@ oven.start() wsocks = [] wsocks_control = [] +def notifyAll(message): + message_json = json.dumps(message) + print "sending to %d clients: %s"%(len(wsocks),message_json) + for wsock in wsocks: + if wsock: + try: + wsock.send(message_json) + except: + print "Could not write to socket!" + wsocks.remove(wsock) + else: + wsocks.remove(wsock) + class OvenWatcher(threading.Thread): def __init__(self,oven): threading.Thread.__init__(self) self.oven = oven - + def run(self): while True: oven_state = self.oven.get_state() notifyAll(oven_state) time.sleep(1) - + ovenWatcher = OvenWatcher(oven) ovenWatcher.start() @app.route('/run') def start_oven(): oven.run_profile("abc") - + return "Starting" @app.route('/control') @@ -39,7 +52,7 @@ def handle_control(): wsock = env.get('wsgi.websocket') if not wsock: abort(400, 'Expected WebSocket request.') - + wsocks_control.append(wsock) while True: try: @@ -53,7 +66,7 @@ def handle_control(): oven.abort_run() except WebSocketError: break - + @app.route('/status') def handle_websocket(): @@ -62,7 +75,7 @@ def handle_websocket(): wsock = env.get('wsgi.websocket') if not wsock: abort(400, 'Expected WebSocket request.') - + wsocks.append(wsock) while True: try: @@ -71,18 +84,7 @@ def handle_websocket(): except WebSocketError: break -def notifyAll(message): - message_json = json.dumps(message) - print "sending to %d clients: %s"%(len(wsocks),message_json) - for wsock in wsocks: - if wsock: - try: - wsock.send(message_json) - except: - print "Could not write to socket!" - wsocks.remove(wsock) - else: - wsocks.remove(wsock) + def main(): server = WSGIServer(("0.0.0.0", 8080), app, handler_class=WebSocketHandler) diff --git a/public/index.html b/public/index.html index 15de223..e5908e8 100644 --- a/public/index.html +++ b/public/index.html @@ -177,8 +177,8 @@ function updateProgress(percentage){ } -var s = new WebSocket("ws://10.1.1.110:8080/status"); -var c = new WebSocket("ws://10.1.1.110:8080/control"); +var s = new WebSocket("ws://localhost:8080/status"); +var c = new WebSocket("ws://localhost:8080/control"); c.onmessage = function(e)