Skip to content

Instantly share code, notes, and snippets.

@adrianlzt
Created July 30, 2025 10:58
Show Gist options
  • Save adrianlzt/00b03c5e7ceba5111f2024f4af9ac7ac to your computer and use it in GitHub Desktop.
Save adrianlzt/00b03c5e7ceba5111f2024f4af9ac7ac to your computer and use it in GitHub Desktop.

Revisions

  1. adrianlzt created this gist Jul 30, 2025.
    40 changes: 40 additions & 0 deletions get_handles.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    #!/usr/bin/env -S uv run --script
    # /// script
    # requires-python = ">=3.10"
    # dependencies = [
    # "bleak",
    # ]
    # [tool.uv]
    # exclude-newer = "2025-07-03T00:00:00Z"
    # ///

    import asyncio
    import sys
    from bleak import BleakClient


    async def main(mac_address):
    def disconnected_callback(client):
    print("Disconnected callback called")

    async with BleakClient(
    mac_address, timeout=15, disconnected_callback=disconnected_callback
    ) as client:
    print(f"Connected to {mac_address}")

    print("Services and characteristics:")
    for service in client.services:
    print(f" Service: {service}")
    for char in service.characteristics:
    print(
    f" Characteristic: {char}, properties: {char.properties}"
    )


    # Para poder lanzarlo manualmente
    if __name__ == "__main__":
    if len(sys.argv) < 2:
    print(f"Usage: {sys.argv[0]} <MAC_ADDRESS>")
    sys.exit(1)
    mac = sys.argv[1]
    asyncio.run(main(mac))