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

bluepy.btle.BTLEManagementError: Failed to execute management command 'le on' (code: 17, error: Invalid Index) #477

Open
Ajith61 opened this issue Apr 21, 2022 · 2 comments

Comments

@Ajith61
Copy link

Ajith61 commented Apr 21, 2022

bluepy.btle.BTLEManagementError: Failed to execute management command 'le on' (code: 17, error: Invalid Index)

@maciej-napora
Copy link

Does this help? #313

@myfingerhurt
Copy link

myfingerhurt commented Jul 21, 2022

@maciej-napora
I have the same issue, with sudo doesn't work either.

RPI4B Ubuntu 20.04 LTS

python3
Python 3.8.10 (default, Mar 15 2022, 12:22:08)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import bluepy
>>> scanner = bluepy.btle.Scanner(0)
>>> devices = scanner.scan(5)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/dist-packages/bluepy/btle.py", line 852, in scan
    self.start(passive=passive)
  File "/usr/local/lib/python3.8/dist-packages/bluepy/btle.py", line 790, in start
    self._mgmtCmd("le on")
  File "/usr/local/lib/python3.8/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 'le on' (code: 17, error: Invalid Index)
>>>  

Solution

I have solved this problem on RPI4B Ubuntu 20.04 LTS 5.4.0-1066-raspi.

  • Step 1, found a solution in here, but didn't work at first
sudo apt-get purge pi-bluetooth
sudo apt-get purge bluez
sudo apt-get purge bluez-firmware

# After that install the pi-bluetooth
sudo apt-get install pi-bluetooth

After done the above, ran into this bug ,systemctl status hciuart.service couldn't start due to this error /90-pi-bluetooth.rules:14 Invalid value, they said you need ran this sudo apt install linux-modules-extra-raspi, but this didn't work on 20.04 LTS, so I did apt update && apt upgrade -y reboot the system apt autoremove.

  • Step 2, hcitool dev got positive feedback
$ hcitool dev
Devices:
        hci0    DC:A6:32:6F:1B:04
extra tests, all good

$ hciconfig -a
hci0:   Type: Primary  Bus: UART
        BD Address: xx:A6:xx:6F:xx:04  ACL MTU: 1021:8  SCO MTU: 64:1
        UP RUNNING
        RX bytes:13399 acl:0 sco:0 events:583 errors:0
        TX bytes:3515 acl:0 sco:0 commands:208 errors:0
        Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
        Link policy: RSWITCH SNIFF
        Link mode: SLAVE ACCEPT
        Name: 'RPI4B4G'
        Class: 0x000000
        Service Classes: Unspecified
        Device Class: Miscellaneous,
        HCI Version: 5.0 (0x9)  Revision: 0x156
        LMP Version: 5.0 (0x9)  Subversion: 0x6119
        Manufacturer: Cypress Semiconductor Corporation (305)
$ bluetoothctl
Agent registered
[CHG] Controller XX:A6:XX:6F:1B:XX Pairable: yes
[bluetooth]# scan on
Discovery started
[CHG] Controller XX:A6:XX:6F:1B:XX Discovering: yes
[NEW] Device XX:7D:04:XX:97:XX XX-7D-04-XX-97-XX
[NEW] Device XX:5C:74:XX:AA:3F XX-5C-74-XX-AA-XX
[bluetooth]#

  • Step 3, python tests, all good
$ python3
Python 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bluepy
>>> scanner = bluepy.btle.Scanner(0)
>>> devices = scanner.scan(5)
>>> for device in devices:
...   print('address : %s' % device.addr)
...
address : XX:f2:XX:0b:dc:XX
address : XX:92:XX:1e:09:XX
address : XX:83:XX:59:52:XX

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

3 participants