hcitool lescan shows I/O error

I'm trying to do a lescan using hcitool on the raspberry pi.

The command prints out

Set scan parameters failed: Input/output error. 

I'm not sure, what exactly happens here. My iPhone is advertising here.

I'm using a BLE dongle from IOGear.

However, if I restart my machine, it shows the a MAC address after I issue the lescan command, and starts showing the same error after I issue the lescan command a couple of more times. Is it like, the lescan command cannot be issued more than once?


Solution 1:

That happens often really often to me. I'm developing with it and it just happens from time to time. I was also able to reproduce your error within 5 minutes ;-) I'm running bluez v.5.17. However i can run lescan more than one time without this error.

hcitool lescan
Set scan parameters failed: Input/output error

try:

hciconfig hci0 down
hciconfig hci0 up

and check the status afterwords.

if this doesn't work or it hangs in DOWN status, try:

service bluetooth restart
service dbus restart

(all commands as superuser)

And close all application that may access bluetooth. For example hcidump.

If that doesn't work you normally have to unplug it. But there is another dirty hack to do this. It works by setting the authorized to 0 and than 1 again. This forces the usb dongle to init.

lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. 
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. 
Bus 001 Device 004: ID 0a5c:21e8 Broadcom Corp. 


cd /sys/bus/usb/devices/

grep -i -s -r 0a5c *
…
1-1.2/idVendor:0a5c
…

cd 1-1.2

echo 0 > authorized
echo 1 > authorized

Solution 2:

Upgrading to bluez v5.43 fixed this for me.

To upgrade to the newest bluez, you need to do a "manual" installation (not apt-get), downloading from the bluez website. I recommend this video walkthrough if you are new installing packages or need help.

After installing the latest bluez, I had to run a couple commands before it worked.

  1. systemctl daemon-reload : Restarts the system daemon.

  2. sudo service bluetooth restart : Restarts the Bluetooth service.

  3. sudo hciconfig hci0 up : This was needed for my Raspberry Pi 3, with the built-in BT found at hci0.

After these commands, sudo hcitool lescan and its variants all seem to work.

Solution 3:

I had the same error with hcitool, while bluetoothctl worked just fine. Then I ran across this article stating that all "tools using raw socket shall be considered deprecated" (hcitool, hcicfg, etc.).

So maybe just open bluetoothctl and issue a scan on command.

Solution 4:

sudo service bluetooth restart helps me on Raspibian Buster.

in case of Set scan parameters failed: Input/output error. error in sudo hcitool lescan.

But is is occuring randomly again, so some system library has probably some issue.

Solution 5:

I have removed Bluez and then I just installed it again, and it worked for me:

sudo apt remove --purge bluez bluez-* -y


apt install bluez

And then

hcitool lescan 

That should be enough.