[Python] Python Bleak start_notify callback not invoked

Discussão em 'Python' iniciado por Stack, Março 4, 2025.

  1. Stack

    Stack Membro Participativo

    I tried to connect my ble device using Python bleak module. The device is getting scanned and connected. I try to enable notification for one of the characteristic using start_notify function.

    await client.start_notify(notify_char,notify_callback)
    def notify_callback(handle, data):
    print(handle, data)


    The notify_callback function is not getting invoked.

    Any pointers on how to get data notified continously from ble.

    Full code:

    import asyncio
    import sys from bleak
    import BleakClient

    notify_char = "2ea78970-7d44-44bb-b097-26183f402401"

    def notify_callback(handle: int, data: bytearray):
    print(f"{handle}: {data}")

    async def main(address):
    async with BleakClient(address) as client:
    if (not client.is_connected):
    raise "client not connected"
    services = await client.get_services()
    await client.start_notify(notify_char,notify_callback)
    await asyncio.sleep(5.0)
    await client.stop_notify(notify_char)

    Continue reading...

Compartilhe esta Página