From da5c1c156a550d821361aba65b4b63aaa703bd66 Mon Sep 17 00:00:00 2001 From: "karl.hudgell" Date: Tue, 26 Oct 2021 15:32:50 +0100 Subject: [PATCH] new --- server.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/server.py b/server.py index 37efc27..8973111 100644 --- a/server.py +++ b/server.py @@ -1,11 +1,13 @@ from flask import Flask, request import os -import sys +import subprocess from colormap import rgb2hex +from tenacity import * app = Flask(__name__) +@retry @app.route("/on") def on(): os.system( @@ -14,6 +16,7 @@ def on(): return "On" +@retry @app.route("/off") def off(): os.system( @@ -22,6 +25,7 @@ def off(): return "Off" +@retry @app.route("/colour") def hello(): # a = request.query_string @@ -33,15 +37,15 @@ def hello(): str = "56" + hex + "00f0aa" try: - subprocess = os.Popen("echo Hello World", shell=True, stdout=os.PIPE) - subprocess_return = subprocess.stdout.read() - print(subprocess_return) + result = subprocess.run( + [ + f"gatttool -i hci0 -b b2:3b:03:00:14:d6 --char-write-req -a 0x0009 -n {str}" + ], + stdout=subprocess.PIPE, + ).stdout.decode("utf-8") + if result != "Characteristic value was written successfully": + raise Exception("Didn't work") + else: + return request.query_string except print(0): pass - - - - os.system( - f"gatttool -i hci0 -b b2:3b:03:00:14:d6 --char-write-req -a 0x0009 -n {str}" - ) - return request.query_string