View Full Version : Bluetooth proximity detection
baksiidaa
12-12-2007, 03:47 PM
There's a number of programs and scripts floating around for desktop computers that can perform specific actions when a known bluetooth device is in range. One use is to automatically lock and unlock your computer when your cell phone leaves and enters the area of the computer, respectively, so that, as long as you keep your cell phone with you, the computer locks when you leave your desk and unlocks when you come back.
To get to the point, I was wondering if there was a good use for such a program/applet on my internet tablet. One I can think of is to unmute the speakers and play an alarm if my cell phone goes out of range, which in effect would sound an alarm if I put down my N800 somewhere and forgot to take it when I left (presuming I didn't leave my cell phone as well).
Does anyone have any ideas about other practical uses of bluetooth proximity detection? Has anyone played with it on their tablet?
If you have linux and kde, it's by default in.
Kdebluetooth and bluez3.
I use it to lock my laptop when the nokia arrives but never thought about the opposite..
Did anybody port kdebluetooth on the device?
Found this (http://gentoo-wiki.com/TIP_Bluetooth_Proximity_Monitor) also
Yesterday I thought about this and made a 'quick and dirty' shell script:
Put this on the nokia::
#/bin/sh
# Script to execute a command when going too far and one when being near enough from the other adapter
# When going too far
cmd1="xmms -u"
# When going too near
cmd2="xmms -p"
# The other endpoint
badr="01:02:03:04:05:06"
# Threshold level
lvl="-4"
# On startup, if the device is close enough, don't execute anything
on=1
sudo hcitool cc ${badr}
sleep 1
while /bin/true
do
l=`sudo hcitool tpl ${badr} | tail -1 | cut -f 2 -d':'
# echo "Power=$l"
if [ "$l" -gt $lvl ] && [ $on == 1 ]
then
echo "Too far"
${cmd1}
on=0
elif [ "$l" -lte $lvl ] && [ $on == 0 ]
then
echo "Near enough"
${cmd2}
on=1
fi
sleep 3
done
You will need to grant your user the right to execute hcitool as root:
As root:
EDITOR=/bin/vi visudo
Add this line at the end of the file:
user ALL = NOPASSWD: /usr/bin/hcitool
If you do something stupid in this file, your device is good for reflashing, so take care.
This example uses xmms because that's the only one I know how to use, replace cmd1 and cmd2 by your favorite app!
Now what can be execute? Humm
cycroft
12-28-2007, 01:40 PM
how do i get hcitool on OS2008
tarek
10-20-2008, 04:20 PM
I find there are a few things that don't work so well in this script. I am using it within ubuntu on my desktop, so perhaps that is part of the issue? Anyhow, here is a revised script with a few key changes:
1. It doesn't respond immediately to "too far" - it waits until the third consecutive reading. I found that in my setup, it was far too disruptive, since it occasionally detected "too far" without any real movement of the bluetooth device. I figure that if walking away from something, probably having three cycles is fine. On the flip side, on the first "near enough", it starts playing.
2. It uses RSSI instead of TPL. TPL seemed less responsive to the small distances over which I use the system.
3. Miscellaneous bash fixes, including "le" instead of "lte", since bash doesn't take "lte".
#/bin/bash
# Script to execute a command when going too far and one when being near enough from the other adapter
# When going too far
cmd1="rhythmbox-client --pause"
# When going too near
cmd2="rhythmbox-client --play"
# The other endpoint
badr="00:19:1D:AB:98:23"
# Threshold level
lvl="-4"
# On startup, if the device is close enough, don't execute anything
on=1
smooth=0
while /bin/true
do
l=`hcitool rssi ${badr} | tail -1 | cut -f 2 -d':'`
# echo "Power=$l"
if [ "$l" -le $lvl ] && [ $on == 1 ]
then
if [ $smooth == 2 ]
then
echo "Too far"
${cmd1}
on=0
smooth=0
else
echo "Are we too far?"
let smooth=smooth+1
fi
elif [ "$l" -gt $lvl ]
then
if [ $on == 0 ]
then
echo "Near enough"
${cmd2}
on=1
else
smooth=0
fi
fi
sleep 3
done
allnameswereout
10-20-2008, 05:18 PM
BlueProximity (http://blueproximity.sourceforge.net). I've installed it on my laptop running Ubuntu but haven't tried it yet. Its a GNOME app (with a nice panel), so should be easy to get working in Maemo.
Use l2ping (from bluez-utils-test) for the device. It will sit there and generally not interfere (see my minigpsd app thread for discussion). It will return 0 or 1 if it sees the device or not.
You can add a file with the following line to /etc/sudoers.d:
user ALL = NOPASSWD: /usr/bin/l2ping *
then do "update sudoers" as root - this will allow you to do
sudo /usr/bin/l2ping -t 1 -c 1 <btaddr>
e.g.
#!/bin/sh
$BTADDR=<address>
while true; do
#(device near state - add commands)
while sudo /usr/bin/l2ping -t 1 -c 1 $BTADDR >/dev/null 2>/dev/null; do
sleep 15
done
#(device away state - add commands)
until sudo /usr/bin/l2ping -t 1 -c 1 $BTADDR >/dev/null 2>/dev/null; do
sleep 3
done
done
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.