Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connection bleak timeout error from central device #377

Closed
ethanHuntoo7 opened this issue Dec 3, 2020 · 8 comments
Closed

connection bleak timeout error from central device #377

ethanHuntoo7 opened this issue Dec 3, 2020 · 8 comments
Labels
Backend: BlueZ Issues and PRs relating to the BlueZ backend

Comments

@ethanHuntoo7
Copy link

  • bleak version: 0.9.1
  • Python version: 3.7
  • Operating System: raspbian buster-lite
  • BlueZ version (bluetoothctl -v) in case of Linux: 5.50

Description

I was simply trying to connect a peripheral device with a central device using bleak nordic service

What I Did

first I ran a peripheral device with an advertisement that can be seen in my android scanning ble app

then in central deivce I just ran client code in the below link https://github.com/adafruit/Adafruit_CircuitPython_BLE/blob/master/examples/ble_uart_echo_client.py

it start scanning and then scanning stop after trying to make a connection with the bellow error

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/bleak/backends/bluezdbus/client.py", line 135, in connect
    ).asFuture(loop)
txdbus.error.RemoteError: org.freedesktop.DBus.Error.UnknownObject: Method "Connect" with signature "" on interface "org.bluez.Device1" doesn't exist


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "testClient.py", line 33, in <module>
    ble.connect(advertisement)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_ble/__init__.py", line 305, in connect
    connection = self._adapter.connect(advertisement.address, timeout=timeout)
  File "/usr/local/lib/python3.7/dist-packages/_bleio/adapter_.py", line 373, in connect
    return self.await_bleak(self._connect_async(address, timeout=timeout))
  File "/usr/local/lib/python3.7/dist-packages/_bleio/adapter_.py", line 134, in await_bleak
    return future.result(timeout)
  File "/usr/lib/python3.7/concurrent/futures/_base.py", line 432, in result
    return self.__get_result()
  File "/usr/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result
    raise self._exception
  File "/usr/local/lib/python3.7/dist-packages/_bleio/adapter_.py", line 384, in _connect_async
    await client.connect(timeout=timeout)
  File "/usr/local/lib/python3.7/dist-packages/bleak/backends/bluezdbus/client.py", line 142, in connect
    self.address
bleak.exc.BleakError: Device with address b8:27:eb:96:30:96 could not be found. Try increasing `timeout` value or moving the device closer.
@hbldh
Copy link
Owner

hbldh commented Dec 3, 2020

Have you tried the recommendation in the exception? To increase the timeout?

@dlech dlech added the Backend: BlueZ Issues and PRs relating to the BlueZ backend label Dec 7, 2020
@dlech
Copy link
Collaborator

dlech commented Dec 9, 2020

I think I have found the problem. For some types of devices (something to do with random address maybe?), the device is removed from BlueZ as soon as scanning is stopped. So if you try to connect to that device after scanning is stopped, it will fail.

As a workaround, try connecting before stopping scanning.

@dlech
Copy link
Collaborator

dlech commented Dec 9, 2020

Also see #363

@dlech
Copy link
Collaborator

dlech commented Dec 13, 2020

It also looks like there is a new experimental BlueZ adapter API that could be for just such an issue: https://github.com/bluez/bluez/blob/98f5da02ce148a61efdfb2557152448f04bab51f/doc/adapter-api.txt#L170-L206

@ethanHuntoo7
Copy link
Author

ethanHuntoo7 commented Dec 16, 2020

bleak version: 0.10.0
Python version: 3.7
Operating System: raspbian buster-lite

now I'm using bleak 0.10.0

and it is giving me a different error

Traceback (most recent call last):
  File "testClient.py", line 29, in <module>
    ble.connect(advertisement)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_ble/__init__.py", line 305, in connect
    connection = self._adapter.connect(advertisement.address, timeout=timeout)
  File "/usr/local/lib/python3.7/dist-packages/_bleio/adapter_.py", line 373, in connect
    return self.await_bleak(self._connect_async(address, timeout=timeout))
  File "/usr/local/lib/python3.7/dist-packages/_bleio/adapter_.py", line 134, in await_bleak
    return future.result(timeout)
  File "/usr/lib/python3.7/concurrent/futures/_base.py", line 432, in result
    return self.__get_result()
  File "/usr/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result
    raise self._exception
  File "/usr/local/lib/python3.7/dist-packages/_bleio/adapter_.py", line 384, in _connect_async
    await client.connect(timeout=timeout)
  File "/usr/local/lib/python3.7/dist-packages/bleak/backends/bluezdbus/client.py", line 103, in connect
    "Device with address {0} was not found.".format(self.address)
**bleak.exc.BleakError: Device with address b8:27:eb:96:30:96 was not found**

@dlech
Copy link
Collaborator

dlech commented Dec 16, 2020

If you run bluetoothctl on the RPi in a separate terminal window what do you see when you run your Python script? In my case, saw a bunch of RSSI property changes while it was advertising, then the device is deleted (denoted by [DEL] as soon as scanning stopped before the connection could be made.

@dlech
Copy link
Collaborator

dlech commented Dec 26, 2020

Also, please try the dbus-next-2 branch. I just added something that could help with this.

See #398 (comment) for more info

@dlech
Copy link
Collaborator

dlech commented Sep 3, 2022

closing since this error happened in the txdbus library that is no longer used

@dlech dlech closed this as completed Sep 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend: BlueZ Issues and PRs relating to the BlueZ backend
Projects
None yet
Development

No branches or pull requests

3 participants