hbldh / bleak

A cross platform Bluetooth Low Energy Client for Python using asyncio

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bleak.exc.BleakError: failed to discover services, device disconnected

bisudw opened this issue · comments

  • bleak version: 0.21.1
  • Python version: 3.10
  • Operating System: Ubuntu
  • BlueZ version (bluetoothctl -v) in case of Linux: 5.64

Description

I have a Vernier Caliper from TESA which has a BLE module and it gives data from that BLE Module. I am trying to read the data from the BLE Module. I am ble to read it in My Phone using LightBlue App (a ble scanner app).

What I Did

When I am rnning the Service_Explorer I am able to discover the device and the advertised service UUID is also visible. Its the same service UUID that i get in my phone app.

It looks like this:

E0:4B:16:4A:55:EA: TLC-BLE
--------------------------
AdvertisementData(local_name='TLC-BLE', manufacturer_data={1341: b'\x0800530322\x069E0445'}, service_uuids=['6e400001-b5a3-f393-e0a9-e50e24dcca9e'], tx_power=4, rssi=-49)

But when I am trying to connect to the same BLE device I am getting error which says:

bleak.exc.BleakError: failed to discover services, device disconnected

here is the code which I am using to trying to connect:

import asyncio
from bleak import BleakClient


async def main():
    async with BleakClient("E0:4B:16:4A:55:EA") as client:
        # Read a characteristic, etc.
        print("Connected")

    # Device will disconnect when block exits.
    print("disconnect")

# Using asyncio.run() is important to ensure that device disconnects on
# KeyboardInterrupt or other unhandled exception.
asyncio.run(main())

Logs

Traceback (most recent call last):
  File "/home/biswa/PycharmProjects/BLEScanner/main.py", line 15, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/home/biswa/PycharmProjects/BLEScanner/main.py", line 6, in main
    async with BleakClient("E0:4B:16:4A:55:EA") as client:
  File "/home/biswa/PycharmProjects/BLEScanner/.venv/lib/python3.10/site-packages/bleak/__init__.py", line 565, in __aenter__
    await self.connect()
  File "/home/biswa/PycharmProjects/BLEScanner/.venv/lib/python3.10/site-packages/bleak/__init__.py", line 605, in connect
    return await self._backend.connect(**kwargs)
  File "/home/biswa/PycharmProjects/BLEScanner/.venv/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py", line 268, in connect
    await self.get_services(
  File "/home/biswa/PycharmProjects/BLEScanner/.venv/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py", line 656, in get_services
    self.services = await manager.get_services(
  File "/home/biswa/PycharmProjects/BLEScanner/.venv/lib/python3.10/site-packages/bleak/backends/bluezdbus/manager.py", line 644, in get_services
    await self._wait_for_services_discovery(device_path)
  File "/home/biswa/PycharmProjects/BLEScanner/.venv/lib/python3.10/site-packages/bleak/backends/bluezdbus/manager.py", line 779, in _wait_for_services_discovery
    raise BleakError("failed to discover services, device disconnected")
bleak.exc.BleakError: failed to discover services, device disconnected

Can you run the same program with debug logging enabled? If that doesn't provide enough info you may need to log Bluetooth packets as well.

https://bleak.readthedocs.io/en/latest/troubleshooting.html