Skip to content

Instantly share code, notes, and snippets.

@adrianlzt
Created November 8, 2021 14:48
Show Gist options
  • Select an option

  • Save adrianlzt/92b46d4a86844a0caeda625d49d22a12 to your computer and use it in GitHub Desktop.

Select an option

Save adrianlzt/92b46d4a86844a0caeda625d49d22a12 to your computer and use it in GitHub Desktop.
Get services, characteristics and descriptors for a BLE device
"""
Get services, characteristics and descriptors for a BLE device
"""
import sys
import asyncio
import platform
from bleak import BleakClient
ADDRESS = ( "20:C3:8F:8A:5B:EA")
async def main(address: str):
async with BleakClient(address) as client:
svcs = await client.get_services()
print("Services:")
for service in svcs:
print(f"SERVICE: {service}")
for c in service.characteristics:
print(f" CHARACTERISTIC: uuid: {c.uuid}, handle: {c.handle}, properties: {c.properties}")
for d in c.descriptors:
print(f" DESCRIPTOR: {d}")
print("\n")
if __name__ == "__main__":
asyncio.run(main(sys.argv[1] if len(sys.argv) == 2 else ADDRESS))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment