From 230195bb5c6b613f012ce8be6009b990c1f04dff Mon Sep 17 00:00:00 2001 From: "karl.hudgell" Date: Tue, 26 Oct 2021 15:56:50 +0100 Subject: [PATCH] working --- server.py | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/server.py b/server.py index bacc900..2b872de 100644 --- a/server.py +++ b/server.py @@ -2,14 +2,14 @@ from flask import Flask, request import os import subprocess from colormap import rgb2hex -from tenacity import wait_exponential, retry, stop_after_attempt +from tenacity import retry, stop_after_attempt app = Flask(__name__) @app.route("/on") -@retry(wait=wait_exponential(multiplier=2, min=2, max=30), stop=stop_after_attempt(5)) +@retry(stop=stop_after_attempt(5)) def on(): result = subprocess.run( [f"gatttool -i hci0 -b b2:3b:03:00:14:d6 --char-write-req -a 0x0009 -n cc2333"], @@ -24,7 +24,7 @@ def on(): @app.route("/off") -@retry(wait=wait_exponential(multiplier=2, min=2, max=30), stop=stop_after_attempt(5)) +@retry(stop=stop_after_attempt(5)) def off(): result = subprocess.run( [f"gatttool -i hci0 -b b2:3b:03:00:14:d6 --char-write-req -a 0x0009 -n cc2433"], @@ -39,7 +39,7 @@ def off(): @app.route("/colour") -@retry(wait=wait_exponential(multiplier=2, min=2, max=30), stop=stop_after_attempt(5)) +@retry(stop=stop_after_attempt(5)) def hello(): # a = request.query_string r = int(request.args.get("r")) @@ -49,18 +49,13 @@ def hello(): hex = hex.replace("#", "") str = "56" + hex + "00f0aa" - try: - result = subprocess.run( - [ - f"gatttool -i hci0 -b b2:3b:03:00:14:d6 --char-write-req -a 0x0009 -n {str}" - ], - stdout=subprocess.PIPE, - shell=True, - ).stdout.decode("utf-8") - print(result) - if "Characteristic value was written successfully" not in result: - raise Exception - else: - return request.query_string - except: + result = subprocess.run( + [f"gatttool -i hci0 -b b2:3b:03:00:14:d6 --char-write-req -a 0x0009 -n {str}"], + stdout=subprocess.PIPE, + shell=True, + ).stdout.decode("utf-8") + print(result) + if "Characteristic value was written successfully" not in result: raise Exception + else: + return request.query_string