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
| import asyncio import platform from bleak import BleakClient
async def connect_char(address): async with BleakClient(address) as client: print(f"Connected: {client.is_connected}")
for service in client.services: print(f"[Service] {service}") for char in service.characteristics: if "read" in char.properties: try: value = bytes(await client.read_gatt_char(char.uuid)) print( f"\t[Characteristic] {char} ({','.join(char.properties)}), Value: {value}" ) except Exception as e: print( f"\t[Characteristic] {char} ({','.join(char.properties)}), Value: {e}" )
else: value = None print( f"\t[Characteristic] {char} ({','.join(char.properties)}), Value: {value}" )
for descriptor in char.descriptors: try: value = bytes( await client.read_gatt_descriptor(descriptor.handle) ) print(f"\t\t[Descriptor] {descriptor}) | Value: {value}") except Exception as e: print(f"\t\t[Descriptor] {descriptor}) | Value: {e}")
asyncio.run(connect_char(ADDRESS))
|