iPhone proximity detection with ESP32

Patrick54
Posts: 9
Joined: Tue Jan 05, 2021 9:05 am

iPhone proximity detection with ESP32

Postby Patrick54 » Tue Jan 05, 2021 9:20 am

Hi,

I searched a lot on the web but didn't find any clear information about what I want to do, so I decided to create a post here.

I would like to put in place an ESP32 in a room, that would detect the proximity of a specific iPhone, and send an HTTP request to my home automation system to set the heating in eco or comfort mode depending on the presence of my son in his room.

Sending an HTTP request was the easy part, this is working fine :)

For the proximity detection of the iPhone, I want to use bluetooth. And I would like it to work like it works with my car and my iPhone: I paired the iPhone with the car once, and now each time I enter my car, my iPhone is detected, without having to do anything at all.

Could you please guide me on the way to achieve this?

Patrick

ESP_Minatel
Posts: 361
Joined: Mon Jan 04, 2021 2:06 pm

Re: iPhone proximity detection with ESP32

Postby ESP_Minatel » Tue Jan 05, 2021 9:50 am

Hi,

There are a couple of ways to do that, but I recommend to use iBeacon:

Using iBeacon:

You can listen to the iPhone BLE advertisements and get the iBeacon UUID. See the reference below for the iPhone side.

Turning an ios device into an ibeacon device
I'm not sure about the iPhone side since I have no device to test here.

For the ESP32 side, you can modify the iBeacon example to receive/scan iBeacons by modifying the macro on configuration.

BLE iBeacon Example

Code: Select all

IBEACON_MODE == IBEACON_RECEIVER

After that, just compare the UUIDs of your iPhone.


You can also pair the device to the iPhone and add it to a list of paired devices to auto connect, but It seems more complex for the purpose of your project.

Patrick54
Posts: 9
Joined: Tue Jan 05, 2021 9:05 am

Re: iPhone proximity detection with ESP32

Postby Patrick54 » Tue Jan 05, 2021 10:43 am

Thanks for your reply.

But if I understand correctly, the esp32 would be in receiver mode, which means that the iPhone would be in sender mode, and for this I need an app running all the time in the foreground... Or would the esp32 "see" the iPhone even if no app is running?
Concerning the pairing, it may be needed, as I read that, for privacy reasons, the UUID of the iPhone changes constantly.

Patrick

ESP_Minatel
Posts: 361
Joined: Mon Jan 04, 2021 2:06 pm

Re: iPhone proximity detection with ESP32

Postby ESP_Minatel » Tue Jan 05, 2021 12:06 pm

No problem!

Yes, the ESP32 will be continuously scanning BLE devices. If your iPhone is configured in discoverable mode you'll detect it, but not as a iBeacon device.

As I mention it, I am not familiar with iPhone to give you more details on it. But let's try the following:

You'll need to filter using MAC address. For privacy reasons, some companies are using random MAC address on WiFi while not connected to a known router.
The same can be applied to the BLE MAC, and since this is undocumented, it's quite challenging for specific phone detection.

Using a specific app could solve this, or you can try to use the first part of the MAC address and filter it by vendor (the company ID).

You can find the vendor list here Vendor List

Patrick54
Posts: 9
Joined: Tue Jan 05, 2021 9:05 am

Re: iPhone proximity detection with ESP32

Postby Patrick54 » Tue Jan 05, 2021 3:05 pm

Thanks a lot, I will play a bit with it, and will report here about the results.

Patrick54
Posts: 9
Joined: Tue Jan 05, 2021 9:05 am

Re: iPhone proximity detection with ESP32

Postby Patrick54 » Tue Jan 05, 2021 5:00 pm

So I made some experiments. I can detect the BLE devices around, and get their RSSI to determine if they are close or far.
As I had a high number of devices around, I filtered for the Apple devices (manufacturer data starts with 4c 00) but the problem is that I cannot filter specifically for iPhones, so a Macbook and its bluetooth keyboard are also detected. And as the data is changing regularly, I cannot determine which is what...

So unless someone has the brilliant idea that will save my day, I think I have to go with the more complex approach and pair the iPhone with the ESP32...

ESP_Minatel
Posts: 361
Joined: Mon Jan 04, 2021 2:06 pm

Re: iPhone proximity detection with ESP32

Postby ESP_Minatel » Tue Jan 05, 2021 7:00 pm

Exactly!

This was one of the biggest challenges for contact tracing applications using mobile phones during the COVID outbreak. You can detect it but you can't identify the device itself.
You can try installing some iBeacon app that simulates the device for testing and use the UUID instead of MAC.

In order for you to work around this, you can implement a BLE peripheral device using NimBLE (it consumes less RAM and has smaller footprint) or change it to WiFi scan in promiscuous mode and do the same filtering by MAC address.

NimBLE BLE peripheral

To use WiFi scan without the random MAC privacy feature, you need to be connected to a WiFi router. The bad thing about this method is that you can't control how many packages your mobile will send and sometimes the time window between packages could be several seconds (depending on your mobile activity/power save modes).

enigma-dk
Posts: 1
Joined: Tue Jan 11, 2022 3:43 pm

Re: iPhone proximity detection with ESP32

Postby enigma-dk » Tue Jan 11, 2022 3:53 pm

I know it's an old issue, but I am looking for the same feature, so have you found any solution to the auto-connect from the Iphone to the ESP.
I know as well it's possible as our Ford car's SYNC system is performing the autoconnect to our Iphones.
Any hints

Thanx

Patrick54
Posts: 9
Joined: Tue Jan 05, 2021 9:05 am

Re: iPhone proximity detection with ESP32

Postby Patrick54 » Tue Jan 18, 2022 1:06 pm

Unfortunately, I didn't find a way to make this work.

Who is online

Users browsing this forum: Majestic-12 [Bot] and 129 guests