-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
executable file
·129 lines (115 loc) · 3.38 KB
/
main.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import bluetooth
import KeyboardKey
import KeyboardWriter
import KeyboardProfileItem
# print("performing inquiry...")
#
# nearby_devices = bluetooth.discover_devices(
# duration=8, lookup_names=True, flush_cache=True, lookup_class=False)
#
# print("found %d devices" % len(nearby_devices))
#
# for addr, name in nearby_devices:
# try:
# print(" %s - %s" % (addr, name))
# except UnicodeEncodeError:
# print(" %s - %s" % (addr, name.encode('utf-8', 'replace')))
#
# import sys
# from gattlib import GATTRequester
#
#
# class Reader(object):
# def __init__(self, address):
# self.requester = GATTRequester(address, False)
# self.connect()
# self.request_data()
#
# def connect(self):
# print("Connecting...", end=' ')
# sys.stdout.flush()
#
# self.requester.connect(True)
# print("OK!")
#
# def request_data(self):
# data = self.requester.read_by_handle(0x10)[0]
#
# print("bytes received:", end=' ')
# for b in data:
# print(hex(ord(b)), end=' ')
# print("")
#
#
# if __name__ == '__main__':
#
# Reader('60:64:05:B3:C4:53')
# print("Done.")
# from gattlib import DiscoveryService, GATTRequester
#
#
#
# req = GATTRequester('60:64:05:B3:C4:53')
# req.write_by_handle(0x10, str(bytearray([14, 4, 56])))
# # #
# # import bluetooth
# #
# # print("performing inquiry...")
# #
# # nearby_devices = bluetooth.discover_devices(
# # duration=8, lookup_names=True, flush_cache=True, lookup_class=False, device_id=0)
# #
# # print("found %d devices" % len(nearby_devices))
# #
# # for addr, name in nearby_devices:
# # try:
# # print(" %s - %s" % (addr, name))
# # except UnicodeEncodeError:
# # print(" %s - %s" % (addr, name.encode('utf-8', 'replace')))
#
# from bluepy.btle import Scanner, DefaultDelegate, Peripheral, ADDR_TYPE_RANDOM, BTLEException, AssignedNumbers
#
# # class ScanDelegate(DefaultDelegate):
# # def __init__(self):
# # DefaultDelegate.__init__(self)
# #
# # def handleDiscovery(self, dev, isNewDev, isNewData):
# # if isNewDev:
# # print("Discovered device", dev.addr)
# # elif isNewData:
# # print("Received new data from", dev.addr)
# #
# # scanner = Scanner(iface=0).withDelegate(ScanDelegate())
# # devices = scanner.scan(10.0)
# #
# # for dev in devices:
# # print("Device %s (%s), RSSI=%d dB" % (dev.addr, dev.addrType, dev.rssi))
# # for (adtype, desc, value) in dev.getScanData():
# # print(" %s = %s" % (desc, value))
# # print("--"*30)
# #
# # item = Peripheral()
# # item.connect('60:64:05:B3:C4:53',iface=1)
#
# conn = Peripheral('60:64:05:B3:C4:53')
# try:
# for svc in conn.services:
# print(str(svc), ":")
# for ch in svc.getCharacteristics():
# print(" {}, hnd={}, supports {}".format(ch, hex(ch.handle),
# ch.propertiesToString()))
# chName = AssignedNumbers.getCommonName(ch.uuid)
# if (ch.supportsRead()):
# try:
# print(" ->", repr(ch.read()))
# except BTLEException as e:
# print(" ->", e)
#
# finally:
# conn.disconnect()
bytesa = bytearray()
bytesa.append(0x09)
bytesa.append(0xD7)
bytesa.append(0x03)
lighting_meta_data = bytes([0x09, 0xD7, 0x03])
print()