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

Bluetooth interface requires periodic reset #29

Open
kalbfuss opened this issue Jan 21, 2022 · 3 comments
Open

Bluetooth interface requires periodic reset #29

kalbfuss opened this issue Jan 21, 2022 · 3 comments

Comments

@kalbfuss
Copy link

I noticed that bluetooth connections have a tendency to fail on one of my Raspberry Pi Zero W running ble2mqtt under RaspbianOS (Debian). Initially, ble2mqtt is able to connect to Xiaomi LYWSD03MMC temperature and humidity sensor devices. After a while, connections always fail and I start to see the following error messages in the log:

...
Jan 21 20:50:52 bridge2 ble2mqtt[327]: WARNING:ble2mqtt.ble2mqtt:Error while connecting to Xiaomi_LYWSD03MMC_a4c138736b80, Device with address A4:C1:38:73:6B:80 was >
Jan 21 20:51:53 bridge2 ble2mqtt[327]: ERROR:ble2mqtt.__main__:Caught exception: {'message': 'Task was destroyed but it is pending!', 'task': <Task pending name='Tas>
Jan 21 20:51:53 bridge2 ble2mqtt[327]: ERROR:asyncio:Task was destroyed but it is pending!
Jan 21 20:51:53 bridge2 ble2mqtt[327]: task: <Task pending name='Task-256' coro=<BleakClientBlueZDBus._disconnect_monitor() running at /usr/local/lib/python3.9/dist->
Jan 21 20:51:53 bridge2 ble2mqtt[327]: INFO:ble2mqtt.__main__:Ignore this exception.

After reset of the bluetooth interface, everything seems to work again until the next failure:

$ sudo hciconfig hci0 reset

Any idea, what might be causing this problem? Obviously, I am interested in a stable setup that does not require any manual interventions.

@devbis
Copy link
Owner

devbis commented Jan 22, 2022

Hey, thank you for the report. Unfortunately, this issue cannot be easily fixed. Here is an issue in bleak hbldh/bleak#500
In short, parsing DBUS messages in python is not optimized. And for some reason, the number of messages grows over time, thus consuming more CPU time. For IoT devices it can lead to freezes and outages.

@kalbfuss
Copy link
Author

Thanks for the prompt answer. I am not sure whether it is the same issue. In fact, ble2mqtt does not use a lot of CPU time on the Pi Zero. I periodically see it flashing up in top with about 20% CPU usage, but not more and neither permanently. Besides, the LYWSD03MMC devices do not change their bluetooth address. So this problem might be something else. Would you be interested in a debug level log?

@kalbfuss
Copy link
Author

I should probably add that connection to the sensors is not very reliable as I am operating at the range limit. Ble2mqtt sometimes fails to find and connect to the sensors. Looking at the log I get the impression that the connection task is destroyed, while it is still trying to connect to a device, possibly because the next poll is already due. Might that be the cause of the observed behaviour? In this case it should help to reduce the timeout interval or increase the poll interval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants