All bluetooth devices have a signal strength indicator (RSSI) which you can use to tell the (very rough) distance from the raspberry pi.

Note: works with any BT device including BT headsets/mice
- e.g. use an old small BT headset as a tracker since it's self contained with a battery.

This is widely dependent on your local conditions, and rf interference etc,
so while you won't be able to measure distance hugely accurately, it is enough to reliably distinguish whether the phone/device is:

1. present - in the house
1. in the same room, or
2. close to the bluetooth dongle (a few inches)

but not much more than that - still very useful information - and this is available WITHOUT PAIRING,

This actually looks GREAT. I've been working on this myself for a while now with a package called "blueproximity" but it looks like it's not every well maintained right now...... I've got most of what I need up and running and it seems to be ok... what I'd really like to know is what bluetooth dongle you're using???

I've got an old RocketFish one here and I never get an RSSI value over 1 or 2.... I seem to get -5 to -15 from across the room... -25 if I sit on my iPhone 5 halfway across the apartment.... but even with the phone laying on the table next to my RasPi... I'm only getting 0... once in a while it bounces up to a 2!

Also... in your instructions you show to connect via rfcomm... the test RSSI. My question is... if you disable bluetooth on your phone (should be the same as walking far enough away that it can't connect anymore)... then enable it again, does it reconnect? If not... show are you making it reconnect when the device comes in range again?

stevenmcastano wrote:
Also... in your instructions you show to connect via rfcomm... the test RSSI. My question is... if you disable bluetooth on your phone (should be the same as walking far enough away that it can't connect anymore)... then enable it again, does it reconnect? If not... show are you making it reconnect when the device comes in range again?

Yes, the rfcomm in step 3 reconnects.

Only step 2 (scan) needs to be done when its discoverable - but once you know the MAC address, you don't need to do that ever again.

Thanks again... this was a really good start. What I found though, is that when your device goes out of range and drops the "rfcomm" connection, when it comes BACK in range again... the connection does not auto start again.

So what I needed to do is the following:

1) When the script first runs, attempt to connect to the bluetooth device:

3) When you finally get an "error" response from checking rssi levels, mark the device "NOT connected" and attempt to connect again.

Here is the code I've got written so far... it's sloppy and I'd invite anyone out there to clean it up and repost!
(this script is built to send me notification via Pushover.net when the device is in range vs. out of range, as well as update my home automation system)

It works like a gem so far... it connects and STAYS connected, connects in anywhere from 1 to 3 seconds when the device is finally back in range and reports the RSSI once a second. It's been running for a few days now and I've only had it "disconnect" and miss an RSSI while I was still home twice and the disconnect lasted for under 5 seconds.

My next plan will be to take the RSSI numbers, keep a running average of the last 30 seconds or so and use that to report the "approximate proximity" to the device. From there I will hopefully find a way to run updates from multiple bluetooth connections to the same device (at least 3) from either different bluetooth dongles, or most likely, multiple raspberry pi's around the house so I can "triangulate" where each device is in the house.

My goal is to give the ability to use "indoor location aware" type commands to my home automation system. Like, when using my XBMC remote app on our iPhones... rather than have to hit the settings button and select which XBMC (also running on Raspberry Pi) to connect to, I'll have a single DNS name called "xbmccontrol.myhouse.com" and when the proximity system thinks you've entered a particular room it will remap that DNS entry over to the IP of the XBMC you're near.

The same thing goes for lighting control using Siri-proxy... when you pick up your phone and say "turn the lights on" it will already know where you are, possibly even ASK you when it thinks you're between rooms and help update the control IP.

Hi! What USB dongle are You using?
Are You using an USB hub or straight into the Pi?
Do You know if exists a Bluetooth USB Dongle with the new BLE stack and the old Bluetooth compatibility as well?
Thank you!

Best regards,
Camillo

mikerr wrote:Use your phone's built in bluetooth as a proximity sensor:

All bluetooth devices have a signal strength indicator (RSSI) which you can use to tell the (very rough) distance from the raspberry pi.

Note: works with any BT device including BT headsets/mice
- e.g. use an old small BT headset as a tracker since it's self contained with a battery.

This is widely dependent on your local conditions, and rf interference etc,
so while you won't be able to measure distance hugely accurately, it is enough to reliably distinguish whether the phone/device is:

1. present - in the house
1. in the same room, or
2. close to the bluetooth dongle (a few inches)

but not much more than that - still very useful information - and this is available WITHOUT PAIRING,

Hi,
I wonder if it is possible to send the RSSI data dierctly via Lan to a PC or Server (another RasPi) where you can work with it. For example to find out in which room the person is if there are more than one "Bluetooth-Points".

It's not working as advertised for me either. After the rfcomm connect command, the phone prompts for a pairing PIN. While waiting, the hcitool rssi command returns valid values. This only lasts for a few seconds however. After that, hcitool rssi responds with 'not connected'.

Not sure if it's down to a difference in Android, BlueZ, or the adapter.