-
Notifications
You must be signed in to change notification settings - Fork 283
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
bleak.exc.BleakDBusError #946
Comments
Hi and thank you for opening an issue. I also face issues when trying to use bleak to connect to the eq3 thermostats. import asyncio
from bleak import BleakClient
mac = "x"
async def on_notification(handle, data):
"""Handle Callback from a Bluetooth (GATT) request."""
# The notification handles are off-by-one compared to gattlib and bluepy
pass
async def main(address):
client = BleakClient(address)
try:
await client.connect(timeout=30.0)
print("Connected succesful!")
# 0x421 - 1, copied from eq3bt
await client.start_notify(0x421 - 1, on_notification)
finally:
await client.disconnect()
print("Disconnected!")
asyncio.run(main(mac)) Windows 11
Debian Doesn't crash but hangs instead. Adapter set to hci1 via parameter (not shown in code). bluetoothd -v: 5.55
Thanks! |
@TechHummel, your problems do not seem to match the description of the issue here so should be discussed elsehwere. I would suggest starting a new discussion for that rather than a new issue for this unless you are 90% certain there is actually a bug in Bleak. |
Hi, I have got now a bit different error message - maybe it can help to findout the issue? Difference:
|
@michapr, I would suggest logging Bluetooth packets with Wireshark as described on the troubleshooting page in the Bleak docs to see if there is a problem with the remote device, e.g. it isn't properly responding to requests and causing BlueZ to disconnect. |
I will try to make it, but all these problems came up only after HA update from 2022.01 to 2022.08 - without any other changes. |
eq3bt before 2022.08 relied on bluepy. Homeassistant 2022.07 removed bluepy support which is why eq3bt switched to bleak (for homeassistant). |
@TechHummel @dlech |
@michapr I'm afraid I haven't! I can't get the thermostats to work with bleak at all. I tried using a newer version of bluez which I didn't manage to get working (dependency issues). I'm out of ideas for now. |
I just upgraded my python-eq3bt version to 0.2 (which uses bleak) and have the same issue. I am not able to get it to work with my thermostats. I get the same errors as @michapr gets. It happened for me on my development machine running xubuntu 20.04. Luckily, I have the option to downgrade python-eq3bt to 0.11.2 which uses bluepy and which works fine. Would a Wireshark dump with bluepy help to solve this problem? |
Absolutely. And another dump of the Bleak version to compare it to. |
Here are the details:
Bluepy environment:
Bleak environment:
I executed for both the same commands while capturing:
I also noticed that when executing the commands via bleak, the Bluetooth manager asks for permission to pair with the thermostat. Using bluepy it was not asking it. Here is notably, I captured the bluepy trace before the bleak trace. And the thermostat was not paired according to the Bluetooth manager before and after I used bluepy. After I used bleak, the thermostat appeared as paired. I hope this helps. |
We would need to do the capture with bleak again after removing the device from bluez to ensure that it does a full enumeration of services and characteristics to be sure, but I'm guessing that the device has a Services Changed characteristic and for some reason (in violation of the Bluetooth spec) it requires authentication to enable indications on that characteristic, which is why it is being paired. This is something that BlueZ does automatically, so there isn't anything we can do about it in Bleak. The bluepy library bypasses BlueZ, so it simply connects to the device and writes to a characteristic. It doesn't have all of the overhead of BlueZ enumerating services, negotiating MTU, etc.
Which error specifically? There have been multiple errors reported here. In spite of all of the overhead, it does appear that Bleak did write to handle 0x0411 and receive a notification from handle 0x0421 just as bluepy did. So perhaps the error can just be ignored? |
I recaptured everything with a new thermostat that was never connected to my machine. Here are the commands + errors:
The last command would normally give you the temperature of the thermostat. However, since the connection failed, it gives you this |
This means that your application has more than one asyncio run loop. IMHO, it is best to only have a single run loop for the entire duration of the app. If you must have more than one, you need to be sure to keep objects within the same run loop and not pass them between loops. (This seems completely unrelated to the other errors in this issue) |
This was only the error I could simply reproduce by executing the basic commands from Errors I had were |
@sqall01 Which version of bluez are you using? Thanks! |
|
bluetoothctl -v
) in case of Linux: 5.55-3.1+rpt1Description
Want to integrate eq3 thermostat and testing the connection.
eq3cli --mac 00:1A:22:08:BF:D6
Scan was working, see the MAC address.
What I Did
Have placed the device about 2 meters from BT - USB stick, made scan, was working.
(also tried bluetoothctl power off / bluetoothctl power on - with no changes in result)
Any idea what can be the reason?
(was working before with old Home Assistant installation at same Raspberry with same adapter - but software was updated)
Thanks!
The text was updated successfully, but these errors were encountered: