monojohnny monojohnny - 28 days ago 7
Linux Question

Bluetooth Low Energy : Passive Scan - but do not loop forever?

Referencing this post I have successfully managed to get a Linux Device (A Raspberry Pi Model A+) to switch my Bluetooth 4.0 USB dongle into the 'advertising' state:

sudo hciconfig hci0 leadv 3


sudo hciconfig hci0 leadv 0

I verified this using an Ipod running the 'LightBlue Explorer' App.

All good so far.

From another Linux box (another Pi) which also has a Bluetooth 4.0 dongle; I can also see the device, using this command:

sudo hcitool lescan --passive

Which returns something like this:

LE Scan ...
xx:xx:xx:xx:xx:xx (unknown)
yy:yy:yy:yy:yy:yy (unknown)
xx:xx:xx;xx:xx:xx (unknown)

But the command loops around constantly refreshing the list of devices.

So my main question is: is there a variation of the command that can be run, listen for (say) 5 seconds; return the list of devices that it found to be advertising and exit ?

I want to build a simple script (or Python program ideally) that will periodically wake up, listen (passively) for advertising traffic for a few seconds, and then return the list of source devices.

Additionally: I'm not sure why the the command shows 'unknown' for the devices it finds. (Whereas the LightBlue does identify the name).


There is no argument in hcitool for that, however here are some options

  • timeout 15s hcitool lescan This will run the scan for 15s
  • hcitool lescan --duplicates This will report each device only once

About (unknown): I assume your peripheral does not include the Bluetooth name in the advertising or even not at all.

--passive tells your HCI Device to not request the ScanResponse (which probably contains the name), thus the name remains unknown, whereas the iOS APIs do an active scan and receive the name.