From 541fc7dc6a07a7d7fcbb9730e08a53b795a59e64 Mon Sep 17 00:00:00 2001 From: "karl.hudgell" Date: Tue, 26 Oct 2021 15:48:40 +0100 Subject: [PATCH] new try --- server.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/server.py b/server.py index 14e62e0..a2a3723 100644 --- a/server.py +++ b/server.py @@ -10,19 +10,31 @@ app = Flask(__name__) @retry @app.route("/on") def on(): - os.system( - f"gatttool -i hci0 -b b2:3b:03:00:14:d6 --char-write-req -a 0x0009 -n cc2333" - ) - return "On" + result = subprocess.run( + [f"gatttool -i hci0 -b b2:3b:03:00:14:d6 --char-write-req -a 0x0009 -n cc2333"], + stdout=subprocess.PIPE, + shell=True, + ).stdout.decode("utf-8") + print(result) + if "Characteristic value was written successfully" not in result: + raise Exception + else: + return "On" @retry @app.route("/off") def off(): - os.system( - f"gatttool -i hci0 -b b2:3b:03:00:14:d6 --char-write-req -a 0x0009 -n cc2433" - ) - return "Off" + result = subprocess.run( + [f"gatttool -i hci0 -b b2:3b:03:00:14:d6 --char-write-req -a 0x0009 -n cc2433"], + stdout=subprocess.PIPE, + shell=True, + ).stdout.decode("utf-8") + print(result) + if "Characteristic value was written successfully" not in result: + raise Exception + else: + return "Off" @retry @@ -44,6 +56,6 @@ def hello(): ).stdout.decode("utf-8") print(result) if "Characteristic value was written successfully" not in result: - raise Exception("Didn't work") + raise Exception else: return request.query_string