Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Bluetooth people presence detector :)

by Juerd (Abbot)
on Nov 08, 2006 at 14:33 UTC ( [id://582882]=CUFP: print w/replies, xml ) Need Help??

The receptionist here at my office wants to know when I'm away, and I should phone or e-mail every time I leave or arrive (they're pretty low-tech, and don't mind receiving a lot of small e-mails). I tend to forget to let them know. And so does my colleague.

It was time to automate this. As I always carry a mobile phone with me, that has bluetooth enabled for my hands free car kit, I thought it would be neat to use that. Then I don't have to push any button, and can just leave, as long as I don't forget to take my phone.

I bought an extended range USB bluetooth dongle, that works perfectly under Linux. After installing bluez-utils, and compiling a kernel with a bluez stack, I wrote this script:

#!/usr/bin/perl -w use strict; my %phones = ( # Bluetooth addresses '00:16:20:XX:XX:XX' => 'Juerd', 'XX:XX:XX:XX:XX:XX' => 'Foo Bar', ); { package Status; sub new { my ($class, $fn) = @_; my $self = bless {}, $class; open my $fh, '<', $fn or return $self; while (defined (my $line = readline $fh)) { my ($addr, $desc) = split ' ', $line, 2; if ($phones{$addr}) { $self->{ $phones{$addr} } = 1; } } return $self } sub present { my ($self, $who) = @_; $self->{ $who }; } } package main; use POSIX qw(strftime); mkdir "$ENV{HOME}/.btscan" or die $! if not -e "$ENV{HOME}/.btscan"; chdir "$ENV{HOME}/.btscan" or die $!; system 'mv now before'; system 'hcitool scan > now'; my $before = Status->new('before'); my $now = Status->new('now'); my $time = strftime '%Y-%m-%d %H:%M:%S', localtime; my @people = keys %{ { reverse %phones } }; for my $person (@people) { if ($before->present($person) and not $now->present($person)) { print "[$time] $person left\n"; system './left', $person if -x 'left'; } if ($now->present($person) and not $before->present($person)) { print "[$time] $person arrived\n"; system './arrived', $person if -x 'arrived'; } }
And I ran crontab -e to let this script be run every minute:
* * * * * /root/btscan.pl
It now emailed root with concise info about my leaving and arriving. But I wanted something a little user-friendlier, so I wrote this script to send a message:
#!/usr/bin/perl -w use strict; use MIME::Lite; my $to = 'foo@example.com'; my %text = $0 =~ /left/ ? ( subject => "%s is weer weg", data => "Dit is een geautomatiseerd bericht, dat wordt gest +uurd " . "omdat de telefoon van\n%s buiten bereik is." ) : $0 =~ /arrived/ ? ( subject => "%s is er weer", data => "Dit is een geautomatiseerd bericht, dat wordt gest +uurd " . "omdat de telefoon van\n%s binnen bereik is." ) : die "What am I?" ; my $person = shift; my $msg = MIME::Lite->new( From => 'bar@example.org', To => $to, Subject => sprintf($text{subject}, $person), Data => sprintf($text{data}, $person), ); $msg->send;
And symlinked that to ~/.btscan/left and ~/.btscan/arrived.

I've been using this for half a day now, and so far it has worked perfectly.

The server here can tell when I'm gone, so I no longer have to remember to notify people.

Juerd # { site => 'juerd.nl', do_not_use => 'spamtrap', perl6_server => 'feather' }

Updates:
  • Removed unused time handling from mail script
  • Someone told me that almost all USB bluetooth devices work under Linux because it's standardized

Replies are listed 'Best First'.
Re: Bluetooth people presence detector :)
by Limbic~Region (Chancellor) on Nov 08, 2006 at 15:12 UTC
    Juerd,
    So now you just need to modify it to identify signal strength to indicate where in the building you are.

    I am sorry sir, he is in the bathroom er um conference room and can't be disturbed.

    Cheers - L~R

      For that, I would need several bluetooth adapters, and lots of USB extension cords. I think it would be fun to triangulate precise-ish locations, but that's a bit too expensive :)

      Juerd # { site => 'juerd.nl', do_not_use => 'spamtrap', perl6_server => 'feather' }

Re: Bluetooth people presence detector :)
by davido (Cardinal) on Nov 09, 2006 at 05:52 UTC

    What's scary is that Bluetooth makes this possible. Imagine the implications. Right now, we take care to clear our cookies once in awhile so that we can't be tracked by websites. But imagine shopping malls, casinos, and so on, tracking bluetooth devices and profiling them. Eventually lcd and plasma billboards could tailor their ads to high rollers as they walk past, for example. Companies could crop up that specialize in maintaining profile databases across multiple businesses. Data munging could deduce that whenever a particular bluetooth address is nearby someone orders a hamburger with extra pickles......

    I think Juerd's script is pretty cool. But it did open my eyes a little.


    Dave

      This trick works because on my phone, bluetooth is set to "visible". You don't have to do that in order to use bluetooth, but without visibility, you need a connection attempt to find out who's there and who isn't, and the distance to the bluetooth dongle within which a good connection can be made is usually smaller that for scanning.

      Your supermarket would probably more easily scan and recognise your face, just like the people at the supermarket have always been able to.

      Juerd # { site => 'juerd.nl', do_not_use => 'spamtrap', perl6_server => 'feather' }

      Well to be honest they could do this with mobile phones without bluetooth and possibly more reliably: I had a conversation with a senior IT guy at a large UK retailer about using GSM picocells in the stores to do just this - the advantage here is the phone actively registers with the cell rather than being "discovered". I'm sure I've heard of some mobile telco that gives a discount if you are prepared to have location based advertising pushed at you via SMS. And then there is the RFID chip in your store card ...

      /J\

      In terms of total people volumes, a company called shoppertrak has been providing technology to do this for at least 10 years.

      This used a hidden camera, and the people appeared as fuzzy blobs; it was relatively easy to see how long individuals are dwelling at a particular shelf or display. Camera technology has definitely come a long way in the last 10 years, so there are probably many more features available today. I've been out of that sector since May 1997.

      --

      Oh Lord, won’t you burn me a Knoppix CD ?
      My friends all rate Windows, I must disagree.
      Your powers of persuasion will set them all free,
      So oh Lord, won’t you burn me a Knoppix CD ?
      (Missquoting Janis Joplin)

Re: Bluetooth people presence detector :)
by zentara (Archbishop) on Nov 09, 2006 at 13:27 UTC
    While this all seems to be voluntary in your case, your method leaves open the option of you fooling them, by leaving your cell phone in your desk drawer. They already are talking about sub-cutaneous implants for everyone. Right now, it's aimed at school children( and pets), but you can bet that they will push it for all employees, ostensibly for insurance and safety purposes.

    Then there are the secret RFID devices they are coming up with, like on badges, sewn into clothes, etc.


    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: Bluetooth people presence detector :)
by webmind (Acolyte) on Nov 08, 2006 at 15:40 UTC
    uhm,doesn't hcitool cache results?
    hciconfig hci0 down
    hciconfig hci0 up
    should fix that though.. but I wouldn't be too sure on it's reliability

      As Juerd mentions it appears to be to do with the configuration of the system. I've just tested it here and definitely isn't cached.

      /J\

      The results are clearly cached on my laptop, but on the system that use for this script, they're not cached. Maybe the hardware device does the caching, or maybe newer kernels do.

      Juerd # { site => 'juerd.nl', do_not_use => 'spamtrap', perl6_server => 'feather' }

Re: Bluetooth people presence detector :)
by shotgunefx (Parson) on Nov 26, 2006 at 22:32 UTC
    Nice (and scary)++ This could come in handy with my car pc.

    -Lee
    "To be civilized is to deny one's nature."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://582882]
Approved by Corion
Front-paged by Fletch
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2024-03-28 23:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found