After detecting my phone using WiFi (which does only work under Marshmallow while the phone is loading or the display is enabled) and detecting the fitbit device I came back to my original task to detect my phone using Bluetooth.

 

While there are many documents out there that describe this on different Linux and even raspberry variants none of those really worked for me. The raspberry 2 (Debian Jessie) seem to be a bit different there.

First of all you need a Bluetooth USB dongle. I buyed the Logilink BT00015 (available at amazon.com, amazon.de or elsewhere). I would expect that others work, too. But as always: On Linux, drivers can be tricky and it’s always good to know working hardware.

Before installing drivers it is always a good idea to update everything:

Then install the libraries needed for bluetooth

I received an error that some dependencies could not be resolved. I fixed that by entering the following commands:

Now insert the USB dongle and restart the raspberry

To check if the USB-dongle is detected,  enter the following command:

This lists all USB devices. There should be one offering Bluetooth – services

Now lets check if the Bluetooth itself works:

The response should now contain the word “Running”:

Now it’s time to check for devices. Do nothing with your phone right now and enter:

This should display all Bluetooth-devices in Range. As you haven’t done anything with your phone yet it should not be displayed there. The output should be something like this:

 

(I modified the MAC addresses. I am not absolutely sure if anyone could do evil things using the MACs, but I prefer not to find that out 🙂 )

Now put your phone into discovery mode. On Android Marshmallow you just have to enter your Bluetooth-settings for this. Then re-scan your devices. There should be one more, now:

Now just note your Mac-Address. We will not pair our device. That takes a few steps and additional packages and additional problems. Pairing is not needed once we know the mac-address.

Now we cam just check the presence by using the info command. Simply leave your Bluetooth-settings on the phone and enter

Event though your phone isn’t in discovery-mode anymore you will get some status information like the device name:

if you turn off Bluetooth on your phone and re-enter that command you will receive a different response:

So that’s it. Just use the good old grep in your bash-script to check whether the phone is there or not:

Again: Have fun 🙂