IanHarvey / bluepy

Python interface to Bluetooth LE on Linux
Other
1.58k stars 490 forks source link

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

Open Ajith61 opened 2 years ago

Ajith61 commented 2 years ago

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

maciej-napora commented 2 years ago

Does this help? https://github.com/IanHarvey/bluepy/issues/313

myfingerhurt commented 1 year ago

@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.

After that install the pi-bluetooth

sudo apt-get install pi-bluetooth

After done the above, ran into this [bug](https://bugs.launchpad.net/ubuntu/+source/pi-bluetooth/+bug/1944027) ,`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


<details><summary>extra tests, all good</summary><p>

$ 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]#

</p></details>

- 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