new
This commit is contained in:
parent
6bf43da152
commit
da5c1c156a
26
server.py
26
server.py
@ -1,11 +1,13 @@
|
|||||||
from flask import Flask, request
|
from flask import Flask, request
|
||||||
import os
|
import os
|
||||||
import sys
|
import subprocess
|
||||||
from colormap import rgb2hex
|
from colormap import rgb2hex
|
||||||
|
from tenacity import *
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@retry
|
||||||
@app.route("/on")
|
@app.route("/on")
|
||||||
def on():
|
def on():
|
||||||
os.system(
|
os.system(
|
||||||
@ -14,6 +16,7 @@ def on():
|
|||||||
return "On"
|
return "On"
|
||||||
|
|
||||||
|
|
||||||
|
@retry
|
||||||
@app.route("/off")
|
@app.route("/off")
|
||||||
def off():
|
def off():
|
||||||
os.system(
|
os.system(
|
||||||
@ -22,6 +25,7 @@ def off():
|
|||||||
return "Off"
|
return "Off"
|
||||||
|
|
||||||
|
|
||||||
|
@retry
|
||||||
@app.route("/colour")
|
@app.route("/colour")
|
||||||
def hello():
|
def hello():
|
||||||
# a = request.query_string
|
# a = request.query_string
|
||||||
@ -33,15 +37,15 @@ def hello():
|
|||||||
|
|
||||||
str = "56" + hex + "00f0aa"
|
str = "56" + hex + "00f0aa"
|
||||||
try:
|
try:
|
||||||
subprocess = os.Popen("echo Hello World", shell=True, stdout=os.PIPE)
|
result = subprocess.run(
|
||||||
subprocess_return = subprocess.stdout.read()
|
[
|
||||||
print(subprocess_return)
|
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):
|
except print(0):
|
||||||
pass
|
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
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user