This commit is contained in:
karl.hudgell 2021-10-26 15:56:50 +01:00
parent a79b3e1f24
commit 230195bb5c

View File

@ -2,14 +2,14 @@ from flask import Flask, request
import os import os
import subprocess import subprocess
from colormap import rgb2hex from colormap import rgb2hex
from tenacity import wait_exponential, retry, stop_after_attempt from tenacity import retry, stop_after_attempt
app = Flask(__name__) app = Flask(__name__)
@app.route("/on") @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(): def on():
result = subprocess.run( result = subprocess.run(
[f"gatttool -i hci0 -b b2:3b:03:00:14:d6 --char-write-req -a 0x0009 -n cc2333"], [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") @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(): def off():
result = subprocess.run( result = subprocess.run(
[f"gatttool -i hci0 -b b2:3b:03:00:14:d6 --char-write-req -a 0x0009 -n cc2433"], [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") @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(): def hello():
# a = request.query_string # a = request.query_string
r = int(request.args.get("r")) r = int(request.args.get("r"))
@ -49,11 +49,8 @@ def hello():
hex = hex.replace("#", "") hex = hex.replace("#", "")
str = "56" + hex + "00f0aa" str = "56" + hex + "00f0aa"
try:
result = subprocess.run( result = subprocess.run(
[ [f"gatttool -i hci0 -b b2:3b:03:00:14:d6 --char-write-req -a 0x0009 -n {str}"],
f"gatttool -i hci0 -b b2:3b:03:00:14:d6 --char-write-req -a 0x0009 -n {str}"
],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
shell=True, shell=True,
).stdout.decode("utf-8") ).stdout.decode("utf-8")
@ -62,5 +59,3 @@ def hello():
raise Exception raise Exception
else: else:
return request.query_string return request.query_string
except:
raise Exception