This commit is contained in:
karl.hudgell 2021-10-26 15:32:50 +01:00
parent 6bf43da152
commit da5c1c156a

View File

@ -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