diff --git a/picoreflowd.py b/picoreflowd.py index d859b70..7b46837 100644 --- a/picoreflowd.py +++ b/picoreflowd.py @@ -1,4 +1,4 @@ -import threading,time,logging,json +import os,threading,time,logging,json import bottle from gevent.pywsgi import WSGIServer @@ -81,6 +81,26 @@ def handle_control(): except WebSocketError: break +@app.route('/storage') +def handle_storage(): + env = bottle.request.environ; + print env + wsock = env.get('wsgi.websocket') + if not wsock: + abort(400, 'Expected WebSocket request.') + + while True: + try: + message = wsock.receive() + wsock.send("Your message was: %r" % message) + if message == "GET": + log.info("GET command recived") + return getProfiles() + elif message == "PUT": + log.info("PUT command received") + except WebSocketError: + break + @app.route('/status') def handle_websocket(): env = bottle.request.environ; @@ -97,6 +117,21 @@ def handle_websocket(): except WebSocketError: break +def getProfiles(): + script_dir = os.path.dirname(os.path.realpath(__file__)) + path = os.path.join(script_dir,"storage","profiles") + print path + try : + profile_files = os.listdir(path) + except : + profile_files = [] + profiles = [] + for filename in profile_files: + with open(os.path.join(path,filename), 'r') as f: + profiles.append(json.load(f)) + print json.dumps(profiles) + return json.dumps(profiles) + def main(): log.info("Starting picoreflowd") ip = "0.0.0.0" @@ -109,4 +144,3 @@ def main(): if __name__ == "__main__": main() - diff --git a/storage/profiles/lead.json b/storage/profiles/lead.json new file mode 100644 index 0000000..b33a0f8 --- /dev/null +++ b/storage/profiles/lead.json @@ -0,0 +1,5 @@ +{ + "type" : "profile", + "name" : "lead", + "data" : [[0,20],[60,100],[100,180],[300,0]] +} diff --git a/storage/profiles/leadfree.json b/storage/profiles/leadfree.json new file mode 100644 index 0000000..0a33b73 --- /dev/null +++ b/storage/profiles/leadfree.json @@ -0,0 +1,5 @@ +{ + "type" : "profile", + "name" : "leadfree", + "data" : [[0,20],[60,100],[100,200],[300,0]] +}