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
|
"""
2024-12-22 23:07:22,916 __main__ INFO: starting scan...
2024-12-22 23:07:23,257 __main__ INFO: connecting to device...
2024-12-22 23:07:23,910 __main__ INFO: connected
2024-12-22 23:07:23,910 __main__ INFO: [Service] 00001801-0000-1000-8000-00805f9b34fb (Handle: 6): Generic Attribute Profile
2024-12-22 23:07:23,911 __main__ INFO: [Service] 00000000-0000-1000-8000-00805f9b34fb (Handle: 7): Vendor specific
2024-12-22 23:07:23,911 __main__ INFO: [Characteristic] 00000002-0000-1001-8001-00805f9b07d0 (Handle: 10): Unknown (notify)
2024-12-22 23:07:24,173 __main__ INFO: [Descriptor] 00002902-0000-1000-8000-00805f9b34fb (Handle: 12): Client Characteristic Configuration, Value: bytearray(b'\x00\x00')
2024-12-22 23:07:24,174 __main__ INFO: [Characteristic] 00000001-0000-1001-8001-00805f9b07d0 (Handle: 8): SDP (write-without-response,write), Max write w/o rsp size: 253
2024-12-22 23:07:24,174 __main__ INFO: disconnecting...
2024-12-22 23:07:28,414 __main__ INFO: disconnected
"""
import asyncio
import binascii
from bleak import BleakClient
def callback(_: int, data: bytearray):
print("received:", data)
print("received:", data.hex())
print("len:", len(data))
def convertInput(i):
decimal_value = int(i)
hex_string = hex(decimal_value).split('x')[-1]
if len(hex_string) % 2 != 0:
hex_string = '0' + hex_string
byte_array = binascii.unhexlify(hex_string)
return byte_array
async def main():
ble_address = "8D:FE:5B:68:D6:D9"
characteristic = "00000001-0000-1001-8001-00805f9b07d0"
notify_listen = "00000002-0000-1001-8001-00805f9b07d0"
async with BleakClient(ble_address) as client:
#await client.write_gatt_char(characteristic, b"\x00\x01\xf4", response=False)
#await client.write_gatt_char(characteristic, b"\x01\x00\x00", response=False)
#await client.write_gatt_char(characteristic, b"\x02\x00\x00", response=False)
# we’ll do the read/write operations here
print("Connected to BLE device")
print(client.is_connected)
while True:
usduty = input("rgbcw")
# c = convertInput(1)
# duty = convertInput(rgbcw)
# cmd = c + rgbcw
# print("sending command ")
# print(cmd)
await client.write_gatt_char(characteristic, b"\x01\xFF\xFF\xFF\x10\xFF", response=False)
try:
await client.start_notify(notify_listen, callback)
except Exception as e:
return
asyncio.run(main())
|