Univers3
Univers3

Reputation: 933

Home automation with ESP32, bluetooth and iPhone drives me crazy

I'm trying to use the ESP32 to check if my iPhone is in the house using the bluetooth. The problem is that when I scan near devices with the ESP32's bluetooth, the iPhone only sends two things:

The Mac address changes every 15 minutes more or less, so it's useless.

And the UUID is not unique. I find other devices with the same UUID (strange)

Someone knows how can I workaround these limitations and recognise if my iPhone is near or not? Thank you all!

Upvotes: 0

Views: 1164

Answers (1)

Rob Napier
Rob Napier

Reputation: 299495

This is all by design of Bluetooth. Bluetooth intentionally makes tracking unpaired devices difficult. See Bluetooth Technology Protecting Your Privacy for a very high-level overview of how this works.

If you pair with the phone, you can get the IRK (Identity Resolution Key), and with that you get resolve the "real" MAC address and identify the phone. That said, if you're using esp-idf, the code indicates that it doesn't support RPA (Resolvable Private Address). See also BLE generating and resolving random mac addresses does not work correctly where they also suggest this is a limitation of the ESP32.

That said, iPhones do advertise a LocalName, and if this is just for use in your house, and you control your phone's device name, you can just look for that in the advertising packet. Note that the local name may be truncated or eliminated if it is long or there are other things the phone needs to advertise. If it's not advertising it, you can connect and read it from GAP. See How do you get the actual name of a bluetooth low energy device?

Upvotes: 2

Related Questions