@@ -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+
4146async 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