Open Owlie opened 7 years ago
I get the same error running "blescan" in the console. I'm running as root
This happens on one of my Bluetooth dongles ("0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)") but not the other one ("0a5c:21e8 Broadcom Corp. BCM20702A0 Bluetooth 4.0").
The error happens when a random address is set, then scanning is shut down after:
> HCI Event: Command Complete (0x0e) plen 4
LE Set Scan Parameters (0x08|0x000b) ncmd 1
status 0x00
> HCI Event: Command Complete (0x0e) plen 4
LE Set Scan Enable (0x08|0x000c) ncmd 1
status 0x00
> HCI Event: Command Complete (0x0e) plen 4
LE Set Random Address (0x08|0x0005) ncmd 1
status 0x00
> HCI Event: Command Complete (0x0e) plen 4
LE Set Scan Parameters (0x08|0x000b) ncmd 1
status 0x0c
Error: Command Disallowed
There appears to be a race condition between subsequent invocations of "bluepy-helper".
This patch "fixes" it: (By "fixing" I mean it makes it not happen on my particular computer. I didn't dig down through the layers of abstraction to solve it properly.)
diff --git a/bluepy/btle.py b/bluepy/btle.py
index ec950e1..65e6a78 100755
--- a/bluepy/btle.py
+++ b/bluepy/btle.py
@@ -218,6 +218,7 @@ class BluepyHelper:
self._helper.stdin.write("quit\n")
self._helper.stdin.flush()
self._helper.wait()
+ time.sleep(0.1)
self._helper = None
if self._stderr is not None:
self._stderr.close()
I ran into the error on my raspberry pi but it was because I forgot to enable the bluetooth device in the first place :/
@markrages Your delay also works for a frequent BTL Exception Device Disconnected when scanning Frequently.
I understand that it's a workaround but it helped to eliminate the frequent exceptions.
Thanks
Same here, but the patch doesn't work for me... :( Ubuntu 16.04 x64, bluepy version 1.1.2, Python 3.5.
If this helps... This error has occurred when Bluetooth was disabled on my laptop (I didn't realize it). If I enable BT, I don't get that error...
Also running into this on Ubuntu Server 18.04, patch doesn't help.
Try sudo hciconfig hci0 down && sudo hciconfig hci0 up
.
Also finding this issue. It seems to happen particularly often under docker. Worth noting that restarting the interface with hciconfig isn't practical for long running logging applications etc.
Yes, I have this issue, too. Raspian 4.19, Pi3, onboard bt. While hci down/up can clear it, like j616 commented, I need it for a persistent logging application (monitors motion sensors). I also have quite a bit of other software running on this Pi, so I'm testing on a Pi4 with a base Raspian install.
My Pi4 also had issues - the process hung after running for a little while. I ended up switching to a USB-based BT devices (BLED112) with bled112_scanner.py.
I have same issue and it run for while and give me Error:
Traceback (most recent call last):
File "TempHumMonitor.py", line 46, in
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 852, in scan
self.start(passive=passive)
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 797, in start
self._mgmtCmd(self._cmd()+"end")
File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 312, in _mgmtCmd
raise BTLEManagementError("Failed to execute management command '%s'" % (cmd), rsp)
bluepy.btle.BTLEManagementError: Failed to execute management command 'scanend' (code: 11, error: Rejected)
Changing that line worked in my case
devices = scanner.scan(10.0)
to
devices = scanner.scan(10.0, passive=True)
I'm getting the same problem on Raspberry Pi with Raspbian, I treed adding "passive=true", but it no longer finds the devices. Any other ideas?
Try
sudo hciconfig hci0 down && sudo hciconfig hci0 up
.
worked for me on rpiZeroW to solve
bluepy.btle.BTLEManagementError: Failed to execute management command 'scanend' (code: 13, error: Invalid Parameters)
Try
sudo hciconfig hci0 down && sudo hciconfig hci0 up
.worked for me on rpiZeroW to solve
bluepy.btle.BTLEManagementError: Failed to execute management command 'scanend' (code: 13, error: Invalid Parameters)
This seems to have fixed my issue with rejected as well.
bluepy.btle.BTLEManagementError: Failed to execute management command 'scanend' (code: 11, error: Rejected)
I detect the error in my code and run the above commands in my python script like this.
resp = subprocess.call("hciconfig hci0 down && hciconfig hci0 up", shell=True)
大神们,请给个详细方案
Try
sudo hciconfig hci0 down && sudo hciconfig hci0 up
.
This seems to have, at least temporarily, worked around the issue for me.
Trying to read an airthings waveplus via a raspberry pi 3b+ every 15 minutes, posting the results to emoncms, which will sometimes work for weeks before failing, and sometimes fail after a few hours/days.
For me
sudo apt update sudo apt upgrade
solved the issue. (Ubuntu 22.04.2 LTS)
I had similar error on my Raspberry Pi Zero W: Failed to execute mgmt cmd 'scanend'. This did not occur if I manually ran my Python script at the command line; only when I ran via cron. The fix for me was to add a delay to the start of my script to prevent it from running "too early" in the Pi boot process. Either adding sleep command to start of the Python script or to cron seemed to do the trick and eliminate the scanend Rejected error: @reboot sleep 60 && my_script.py
Raspberry pi 3 Model B
Using the example code from http://ianharvey.github.io/bluepy-doc/scanner.html#sample-code
I get this error.