Bleak
Bluetooth Low Energy platform Agnostic Klient for Python
Usage
To discover Bluetooth devices that can be connected to:
import asyncio
from bleak import BleakScanner
async def main():
devices = await BleakScanner.discover()
for d in devices:
print(d)
asyncio.run(main())
Connect to a Bluetooth device and read its model number:
import asyncio
from bleak import BleakClient
address = "24:71:89:cc:09:05"
MODEL_NBR_UUID = "00002a24-0000-1000-8000-00805f9b34fb"
async def main(address):
async with BleakClient(address) as client:
model_number = await client.read_gatt_char(MODEL_NBR_UUID)
print("Model Number: {0}".format("".join(map(chr, model_number))))
asyncio.run(main(address))
Client Services
import asyncio
from bleak import BleakScanner, BleakClient
from PyObjCTools import KeyValueCoding
async def main():
devices = await BleakScanner.discover()
for d in devices:
if KeyValueCoding.getKey(d.details,'name') == 'awesomecoolphone':
myDevice = d
print('Found it')
address = str(KeyValueCoding.getKey(myDevice.details,'identifier'))
async with BleakClient(address) as client:
svcs = await client.get_services()
print("Services:")
for service in svcs:
print(service)
asyncio.run(main())