Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Comment on

( #3333=superdoc: 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/
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 = ''; 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 => '', 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 => '', do_not_use => 'spamtrap', perl6_server => 'feather' }

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

In reply to Bluetooth people presence detector :) by Juerd

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (9)
    As of 2018-06-18 16:15 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (110 votes). Check out past polls.