-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcandelapy_web.py
More file actions
34 lines (26 loc) · 781 Bytes
/
candelapy_web.py
File metadata and controls
34 lines (26 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from flask import Flask
app = Flask(__name__)
import pygatt
import sys
from flask import request
adapter = pygatt.GATTToolBackend()
adapter.start()
print("Trying to connect...")
try:
device = adapter.connect("F8:24:41:C0:71:A7")
except:
print("Connection Error")
finally:
device.char_write_handle(0x001f, bytearray([0x43, 0x67, 0x02]))
print("Now turn the lamp")
@app.route("/yeelight")
def on():
intensity = int(request.args.get('intensity'))
if intensity > 0:
device.char_write_handle(0x001f, bytearray([0x43, 0x40, 0x01])) #on
device.char_write_handle(0x001f, bytearray([0x43, 0x42, intensity])) #intensiy
else:
device.char_write_handle(0x001f, bytearray([0x43, 0x40, 0x02])) #off
return "OK"
if __name__ == "__main__":
app.run(host='0.0.0.0',debug=True)