Skip to content

Commit a0cb0b6

Browse files
wip
1 parent 18292ae commit a0cb0b6

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"type": "debugpy",
1010
"request": "launch",
1111
// "program": "src/__main__.py",
12-
"module": "examples.bluetooth.example_bluetooth",
12+
"module": "examples.mid_level.example_mid_level",
1313
"justMyCode": false,
1414
// "args": ["COM3"],
1515
"console": "integratedTerminal"

examples/bluetooth/example_bluetooth.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,37 @@ def callback(sender: BleakGATTCharacteristic, data: bytearray):
3838
print(f"{sender}: {data}")
3939

4040

41+
def handle_disconnect(device: BleakClient):
42+
"""disco"""
43+
print(f"Device was disconnected, {device}")
44+
45+
4146
async def main() -> int:
4247
"""Main function"""
4348

4449
mid_level_init_guid = "0000abcd-8e22-4541-9d4c-21edae82ed19"
4550
mid_level_init_ack_guid = "0000bcde-8e22-4541-9d4c-21edae82ed19"
4651
print("Scan...")
52+
# devices = await BleakScanner.discover(return_adv=True)
4753
devices = await BleakScanner.discover()
4854

49-
for d in devices:
50-
if d.name == "YOLO":
51-
async with BleakClient(d) as client:
55+
for value in devices:
56+
# device = value[0]
57+
device = value
58+
if device.name == "YOLO":
59+
# print(f"Advertising data: {value[1].manufacturer_data}")
60+
async with BleakClient(device, disconnected_callback=handle_disconnect, timeout=10.0) as client:
61+
# client = BleakClient(device)
62+
# await client.connect()
5263
await print_services(client)
5364

54-
await client.connect()
5565
await client.start_notify(mid_level_init_ack_guid, callback)
5666
# value = await client.read_gatt_char(mid_level_init_guid)
57-
await client.write_gatt_char(mid_level_init_guid, "Hallo".encode("utf-8"), True)
67+
await client.write_gatt_char(mid_level_init_guid, bytes([0xBB]), True)
5868
# value = await client.read_gatt_char(mid_level_init_guid)
5969
# print(value)
6070
await asyncio.sleep(5)
61-
await client.disconnect()
71+
# await client.disconnect()
6272

6373
return 0
6474

0 commit comments

Comments
 (0)