User avatar
simonmcc
Posts: 181
Joined: Mon Aug 19, 2013 10:07 pm

Using Bluetooth to detect when I'm nearby

Tue Dec 17, 2013 3:33 pm

Sorry if there is a simple tutorial for this but I can't find it, and I can't believe no-one is doing this already.

For my next project I would like to add the capability for my pi to detect when I am nearby using the bluetooth of the phone in my pocket.

I don't want my phone to be discoverable all the time, so the two would have to be paired (I don't know how to do this). Then I don't know the mechanism, but is there a program which can run all the time and notify me when it detects my phone in range.

Extras: I would like to know the phone is in range but not necessarily pair with it. It would also be good if it worked the same for the other 3 phones owned by our family.

Background: The project is a garage door controller, which will switch the lights on inside the garage if the door is opening and it is dark. I would like them to stay on based on my proximity, but I wouldn't want the pi to prevent my phone pairing with the bluetooth in my car. This feature would also mean that if I am inside the garage and shut the door the lights will remain on.

Any help appreciated :)
simonmcc.blogspot.com/search/label/pi

User avatar
Douglas6
Posts: 4781
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Using Bluetooth to detect when I'm nearby

Tue Dec 17, 2013 3:59 pm

There's this Adafruit tutorial on making the Pi into an Ibeacon, but that's the other way 'round, and it seems to be Apple specific.
http://learn.adafruit.com/pibeacon-ibea ... spberry-pi
This idea is something I'm interested in as well, I'll add anything I find out here. Shouldn't be hard with a paired device, unpaired (and undiscoverable) I think may not be possible.

patrocks
Posts: 9
Joined: Thu Apr 11, 2013 3:36 pm

Re: Using Bluetooth to detect when I'm nearby

Tue Dec 17, 2013 4:52 pm

I think some people may use phones to turn home automation on via wifi. If your phone is set to connect to your home wifi when in range you could look for it (via ping?) but it wouldn't be able to pin you down room by room.

User avatar
Douglas6
Posts: 4781
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Using Bluetooth to detect when I'm nearby

Tue Dec 17, 2013 6:21 pm

I just found this...looks to be a bluetooth solution: http://www.raspberrypi.org/phpBB3/viewt ... 37&t=47466

User avatar
simonmcc
Posts: 181
Joined: Mon Aug 19, 2013 10:07 pm

Re: Using Bluetooth to detect when I'm nearby

Wed Dec 18, 2013 8:57 am

Douglas6 wrote:I just found this...looks to be a bluetooth solution: http://www.raspberrypi.org/phpBB3/viewt ... 37&t=47466
I tried that last night with an ancient bluetooth dongle I had. lsusb shows it as "Roper Class 1 Bluetooth Dongle" and I did the apt-get installs, and hciconfig -a listed my device but its state was DOWN. hcitool dev and hcitool scan both returned no good results. More googling showed me that the driver that gets automatically loaded for my bluetooth dongle was wrong, and I needed to do this (as root):

Code: Select all

[email protected]:~# echo 'blacklist bnep' >> /etc/modprobe.d/bluetooth.conf
reboot, and it came up showing a state of UP. Then when I made my phone discoverable I was able to find it using

Code: Select all

hcitool scan
and also able to ping it using

Code: Select all

sudo l2ping 00:12:34:56:67:78


From those instructions though I couldn't get it to pair.

This ping also works when the device is not discoverable.

So I'm getting there. I'd need to write a wrapper around l2ping to ping each of a specified list of addresses in turn, I don't really need to know that there are multiple devices in proximity, I only need to detect if any one is there.

I still can't believe that there isn't already a nice precooked solution out there, and I'd like a better solution than having to ping devices in turn
simonmcc.blogspot.com/search/label/pi

ArnieX
Posts: 11
Joined: Fri Oct 19, 2012 4:49 am

Re: Using Bluetooth to detect when I'm nearby

Thu Jan 09, 2014 9:02 am

Better than l2ping is ask for device name HCITOOL NAME E8:39:DF:00:00:00, faster and more reliable thorough many device types. It responds in few seconds with either name or nothing, when nothing, device is not present and if something it will show device name so you can even check if it is still the same name. Furthermore l2ping ask on almost all devices if you want to pair with Raspberry Pi which is something I don't want to see or do. And it has strange behaviour. Hope I added some useful info into place.

MattF
Posts: 55
Joined: Tue Feb 12, 2013 10:01 am

Re: Using Bluetooth to detect when I'm nearby

Thu Jan 09, 2014 2:47 pm

http://www.digifail.com/software/bluelog.shtml

Compiles easily.

It could be wrapped in a simple looping script to parse it's output.

User avatar
simonmcc
Posts: 181
Joined: Mon Aug 19, 2013 10:07 pm

Re: Using Bluetooth to detect when I'm nearby

Thu Jan 09, 2014 4:05 pm

I'll try those suggestions

thanks!
simonmcc.blogspot.com/search/label/pi

Return to “Automation, sensing and robotics”