maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Bluetooth proximity detection (https://talk.maemo.org/showthread.php?t=13089)

baksiidaa 2007-12-12 20:47

Bluetooth proximity detection
 
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?

free 2007-12-12 21:18

Re: Bluetooth proximity detection
 
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 also

free 2007-12-13 09:53

Re: Bluetooth proximity detection
 
Yesterday I thought about this and made a 'quick and dirty' shell script:
Put this on the nokia::

PHP Code:

#/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:
Code:

EDITOR=/bin/vi visudo
Add this line at the end of the file:
Quote:

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 2007-12-28 18:40

Re: Bluetooth proximity detection
 
how do i get hcitool on OS2008

tarek 2008-10-20 20:20

Re: Bluetooth proximity detection
 
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".

Code:

#/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 2008-10-20 21:18

Re: Bluetooth proximity detection
 
BlueProximity. 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.

tz1 2008-10-28 15:04

Re: Bluetooth proximity detection
 
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.

Code:

#!/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


biketool 2013-10-29 05:46

Re: Bluetooth proximity detection
 
I saw this http://www.indiegogo.com/projects/th...-of-defense--3 and thought that we could use the above scripts with a bluetooth module of some sort. Ideally it would be a generic Bluetooth device, maybe a bluetooth-serial adapter which can later be connected to something useful, but which would not interrupt any service on the N900. I have the adapters around to connect to my headlight dynamo making in theory a bluetooth proximity gadget that is charged anytime I use the bike for more then a few meters.
SInce the last post in 2007 has there been any progress or threads on porting a bluetooth proximity alarm app?
We dont have USB 4.0 or the proprietary iPhone app for Cricket so this alternate idea is that you simply bluetooth ping the dumb puck attached to your bicycle and alarm if it gets stolen leaving your proximity, it means you can enjoy your coffee without having to watch the bike 100% of the time. If I had more arduino-fu I would connect an arduino and a brake solenoid to the rear wheel to lock up the bicycle if the bluetooth ping times out while in guard mode so I could rescue the bike on foot, maybe a loud alarm too. I think there are actually GSM modems with GPS for the arduino which is another alternate possibility so it could SMS its location.

rotoflex 2013-10-29 06:55

Re: Bluetooth proximity detection
 
I have been wishing for something similar for the N900 for a long time.

I would love to be able to start certain programs on the N900 when the bluetooth dongle in my car is in range.

biketool 2013-10-29 11:11

Re: Bluetooth proximity detection
 
So for a dumb bluetooth 'puck' say for keeping track of a bicycle or briefcase there is a bluetooth to serial thing on ebay for about $4, $2 for a charge controller, and solder on an old mobile phone battery, everything for under $10 and stick instide a small plastic box with a charge port cut in it.
I think I will order the hardware and publish the .stl files for p3d printing a case once they come.
I would really like a nice QT app rather than the above scripts and a generic launcher.
Sourced from ebay auctions
1 - JY-MCU bluetooth to serial board $1.04(free int'l shipping)
1 - Micro USB 5V 1A Lithium Battery Charging Board $2.37(free int'l shipping)
1 - battery BL-5J (fake) $6.99(free int'l shipping)
1 - (five pack)switches $2.06 (free int'l shipping)
1 - plastic case(I plan to print one)

I imagine that this should be powerful enough for keeping tabs on a bicycle parked on a curb or rack when you are in a coffee shop or restaurant and should run for maybe a week on a charge, the charge board is smart so it wont overcharge the battery and has a microUSB port. The bluetooth gadget is actually a serial adapter so anything you want to serial TTY to can be connected say an arduino with a sound amp and siren or whatever.


All times are GMT. The time now is 22:15.

vBulletin® Version 3.8.8