This commit is contained in:
karl.hudgell 2021-10-26 15:48:40 +01:00
parent b31d16958f
commit 541fc7dc6a

View File

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