BLE Tracker - How to detect Android phone presence?


I am currently trying to use my android smartphone (Google Pixel 4a) as a key for a keyless entry system. The idea is to make the Particle Tracker detect the presence of my phone via BLE. Sofar I have been unable to detect it when using the following code:

 * Project BLETest
 * Description:
 * Author:
 * Date:

#include "Particle.h"


SerialLogHandler logHandler(LOG_LEVEL_TRACE);

// setup() runs once, when the device is first turned on.
void setup() {
  // Put initialization like pinMode and begin functions here.

// loop() runs over and over again, as quickly as it can execute.
void loop() {
  // The core of your code will likely live here.
  Vector<BleScanResult> scanResults = BLE.scan();
  if (scanResults.size()) {"%d devices found", scanResults.size());

        for (int ii = 0; ii < scanResults.size(); ii++) {
            // For Device OS 2.x and earlier, use scanResults[ii].address[0], etc. without the ()
  "MAC: %02X:%02X:%02X:%02X:%02X:%02X | RSSI: %dBm",
                    scanResults[ii].address()[0], scanResults[ii].address()[1], scanResults[ii].address()[2],
                    scanResults[ii].address()[3], scanResults[ii].address()[4], scanResults[ii].address()[5], scanResults[ii].rssi());

            // String name = scanResults[ii].advertisingData().deviceName();
            // if (name.length() > 0) {
            //"Advertising name: %s", name.c_str());
            // }


In the list of the MAC adresses I don’t see the MAC adress of my phone though I opened up the Bluetooth setting. This should indicate that the device is present.

Do any of you know if this works at all with an Android device? Is there something I am missing?

Thanks for any help!

How many scan results do you get?
Have you tried increasing the scan timeout?
Are you sure your phone is visible? You could try a third party app like nRF Connect to check.

I usually get around 46 devices.
I increased the scan timeout from 5 to 20 seconds without success.
Yes the phone is visible and displayed in the nRF Connect App.

Any other guesses?

When I try this with my Android phone I see that it never hands out its actual hardware MAC but always comes up with a new temporary “private resolvable random address” - I see that on both the Boron (I’m running your code on) and nRF Connect.

I can confirm this by switching BT/BLE on and off on my phone in a location where I only have a handful of BT/BLE devices to keep track of.
Alternatively I could adapt the code to only ever list unknown devices and correlate that with me switching BT/BLE on and off on my phone - but for me the test above did it good enough to establish the “hypothesis” :wink:

Also be aware that the address logged by your code is the reverse to what you get from nRF Connect.