2

I am trying to execute a piece of code when a Bluetooth device is in range. What is the best way to do this? I have tried using 'hcitool scan' but that only produces a list of devices that are visable, mine won't be.

2 Answers 2

3

You can only find devices that are either paired or are in visible/discovery mode when you use hcitool. That is because devices that do not meet those conditions simply won't respond when your Bluetooth chip queries for them.

If the device you are trying to detect is a Bluetooth Low Energy (BLE) device, you might be able to see it using hcitool lescan because the discoverability rules for some BLE devices are different. However, this is not guaranteed to work either.

Most non-paired Bluetooth devices will still respond to a Bluetooth "ping", so if you know the address of the Bluetooth device you should be able to use l2ping XX:XX:XX:XX:XX:XX on a schedule and see if you get a response.

1

Using GUI:

  1. Open Terminal and type sudo apt-get install bluetooth bluez blueman. Press enter.
  2. Once the packages have downloaded and installed, type sudo reboot.
  3. To access this menu, on the Raspberry Pi desktop click Menu, located in the upper left corner of the screen, scroll down to Preferences with your cursor and click Bluetooth Manager. From there, you can pair to any nearby devices, or you can make your Raspberry Pi discoverable so you can pair your phone to it from your phone's Bluetooth settings. I hope it will help you.
1
  • I don't necessarily want to pair it, I just want to know when it is around Commented Nov 11, 2018 at 16:11

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.