LED-Control/server.py

38 lines
811 B
Python
Raw Normal View History

2021-10-25 20:04:55 +01:00
from flask import Flask, request
import os
from colormap import rgb2hex
app = Flask(__name__)
2021-10-26 10:39:04 +01:00
@app.route("/on")
2021-10-25 20:04:55 +01:00
def index():
2021-10-26 10:39:04 +01:00
os.system(
f"gatttool -i hci0 -b b2:3b:03:00:14:d6 --char-write-req -a 0x0009 -n cc2333"
)
return "On"
@app.route("/off")
def index():
os.system(
f"gatttool -i hci0 -b b2:3b:03:00:14:d6 --char-write-req -a 0x0009 -n cc2433"
)
return "Off"
2021-10-25 20:04:55 +01:00
2021-10-26 10:33:37 +01:00
@app.route("/colour")
def hello():
# a = request.query_string
r = int(request.args.get("r"))
g = int(request.args.get("g"))
b = int(request.args.get("b"))
hex = rgb2hex(r, g, b)
hex = hex.replace("#", "")
str = "56" + hex + "00f0aa"
os.system(
f"gatttool -i hci0 -b b2:3b:03:00:14:d6 --char-write-req -a 0x0009 -n {str}"
)
return request.query_string