The other day, while I was wating for several GB to transfer over the network at work, I finally got around to setting something that’s been dancing at the back of my mind for a while: computer-based proximity detection using Bluetooth.

I have a Treo 650.  It has Bluetooth.  I also have a USB Bluetooth Adapter.  I originally planned to carry the bluetooth adapter around and hook it up to different computers whenever I wanted to talk to the Treo, but I’ve only been using it at work, so I’ve been leaving the adapter connected to my Linux computer at work.  The thought occurred to me that I could use the Bluetooth adapter to see whether my phone was nearby and do things based on that information.  At least to start, I decided to have the computer lock itself when I wasn’t around.

I have the BlueZ Bluetooth stack installed.  (On Debian, that’s the bluez-utils package.)  They include a l2ping program, but that establishes a full Bluetooth connection with the device, which makes my Treo turn on the screen, play a little sound, and show a pop-up dialog.  That’s a little intrusive for something that I want checked several times a minute.  Some people use hcitool rssi to find out the strength of the phone’s (or other device’s) Bluetooth signal.  That also requires a full Bluetooth connection.  I ended up using hcitool name, which returns the name of the device if it’s found and nothing if it’s not.  More importantly, it doesn’t cause the Treo to do anything but silently send its response, and it works even if the Treo screen is off.

So I now have a stupid little shell script that looks like this:

#!/bin/sh

PHONE_ADDR=01:23:45:67:89:AB
PHONE_NAME="glamdring"
WAIT_TIME=15

while true; do
  if [ "$(hcitool name $PHONE_ADDR)" \!= "$PHONE_NAME" ]; then
    xscreensaver-command -lock
  fi
  sleep $WAIT_TIME
done

There are programs for Windows that do similar things.  Possibly one of the simplest is Blue Lock, which is also open-source (and written in Delphi).  I’m probably just going to write a simple Windows program to listen on the network for a message from my Linux computer to tell it to lock the screen.