Repeated BLE scanning causes BleakDBusError on Raspberry Pi: missing DBus disconnect on scan stop? #1273
Replies: 3 comments 3 replies
-
Ran
|
Beta Was this translation helpful? Give feedback.
-
Seems to be a missing disconnect from the dbus on scan stop()? |
Beta Was this translation helpful? Give feedback.
-
You are not using asyncio correctly. import asyncio
from bleak import BleakScanner
async def main():
while True:
await asyncio.sleep(3) # simulating the other parts of the application
print("Scanning...")
devices = await BleakScanner.disover(timeout=2)
# do stuff with discovered devices
...
if __name__=='__main__':
asyncio.run(main()) |
Beta Was this translation helpful? Give feedback.
-
Description
I am writing a Python application that is intended to run continuously on a RPi. It is supposed to regularly (lets say every 10 sec) perform a BLE scan, and is using bleak to do so. The scan is performed using a start-sleep-stop scan sequence without detection callbacks. After a while (~30 mins), scanner.start() crashes due to a BleakDBusError Exception:
bleak.exc.BleakDBusError: [org.freedesktop.DBus.Error.AccessDenied] Client tried to send a message other than Hello without being registered
This behavior is consistent for two different RPi models (3B+/4), Ubuntu versions (20.04/22.04 LTS), blueZ versions (5.53/5.64) and python versions (3.8.10/3.10.6), which raises the question if this a bleak problem or if I am doing something that I shouldn't be doing, e.g. with regards to the asyncio library. See example below. Any help is greatly appreciated.
What I Did
Minimum working example:
Logs
There are no apparent clues in the log prints using export BLEAK_LOGGING=1. No info with regards to the raised exception/error. No wireshark logs available as of now, but if they are needed to for troubleshooting I will try to acquire them.
Beta Was this translation helpful? Give feedback.
All reactions