Skip to content

z Notes

John Blance edited this page Feb 22, 2024 · 3 revisions

BLE with Bleak

https://nabeelvalley.co.za/docs/iot/bluetooth-intro/

import asyncio
import sys
from bleak import BleakClient

async def main(address):
  async with BleakClient(address) as client:
    if (not client.is_connected):
      raise "client not connected"

    services = await client.get_services()

    for service in services:
      print('\nservice', service.handle, service.uuid, service.description)

      characteristics = service.characteristics

      for char in characteristics:
        print('  characteristic', char.handle, char.uuid, char.description, char.properties)

        descriptors = char.descriptors

        for desc in descriptors:
          print('    descriptor', desc)

if __name__ == "__main__":
  address = sys.argv[1]
  print('address:', address)
  asyncio.run(main(address))

folding comments in markdown

<details>
<summary>Debug info if needed</summary>
dg
sdf
sf

</details>
Debug info if needed dg sdf sf
Clone this wiki locally