I have a Linux (Fedora Core 4) box at home that performs a number of interesting functions including acting as a Bluetooth presence server. When I get home a cron script running every 5 minutes grep's for the MAC address of my mobile phone using the bluetooth hcitool. Once detected it fires off several activities and plays me a little greeting message letting me know how long I've been out and how many emails are waiting etc.
I finally got around to also linking presence to GBPVR. In PostProcessing.bat I added:
echo %1 >> c:\btp\recordings.txt
(the >> appends)
check.sh runs on my linux box and does the following:
#!/bin/sh
# grep for my phone
/usr/bin/hcitool con | grep -q "00:0E:07:E8:07:7E" || (hcitool scan | grep "00:0E:07:E8:07:7E" && hcitool cc 00:0E:07:E8:07:7E )
I created a Windows Share on my GBPVR machine and then mount that share using Samba (also in check.sh):
mount -t smbfs //anya/btp /mnt/btp -o username=foo,password=bar
check.sh maintains my status in where, awaydate and homedate:
# get last status
exec 6<&0
exec < /opt/btp/where
read a1
LASTSTATUS=$a1
exec 0<&6 6<&-
# get last status
exec 5<&0
exec < /opt/btp/homedate
read a1
HOMEDATE=$a1
exec 0<&5 5<&-
# get away date
exec 7<&0
exec < /opt/btp/awaydate
read a1
AWAYDATE=$a1
exec 0<&7 7<&-
# get last recorded shows
exec 4<&0
exec < /mnt/btp/recordings.txt
read a1
read a2
read a3
read a4
read a5
read a6
LASTSHOW1=$a2
LASTSHOW2=$a3
LASTSHOW3=$a4
LASTSHOW4=$a5
LASTSHOW5=$a6
exec 0<&4 4<&-
# parse out the path
echo "Last 5 recorded shows:"
LASTSHOW1=${LASTSHOW1/\"C:recordings/}
LASTSHOW2=${LASTSHOW2/\"C:recordings/}
LASTSHOW3=${LASTSHOW3/\"C:recordings/}
LASTSHOW4=${LASTSHOW4/\"C:recordings/}
LASTSHOW5=${LASTSHOW5/\"C:recordings/}
# extract the directory for the show name announcement
SAYLASTSHOW1=$( echo $LASTSHOW1 | awk '{ show = $1 "-" $2 "-" $3 "-" $4 "-" $5 "-" $6 "-" $7 "-" $8 "-" $9; split(show,shows,"_"); l = length(shows[1]) } { print substr(shows[1], 0, (l/2))}' )
SAYLASTSHOW2=$( echo $LASTSHOW2 | awk '{ show = $1 "-" $2 "-" $3 "-" $4 "-" $5 "-" $6 "-" $7 "-" $8 "-" $9; split(show,shows,"_"); l = length(shows[1]) } { print substr(shows[1], 0, (l/2))}' )
SAYLASTSHOW3=$( echo $LASTSHOW3 | awk '{ show = $1 "-" $2 "-" $3 "-" $4 "-" $5 "-" $6 "-" $7 "-" $8 "-" $9; split(show,shows,"_"); l = length(shows[1]) } { print substr(shows[1], 0, (l/2))}' )
SAYLASTSHOW4=$( echo $LASTSHOW4 | awk '{ show = $1 "-" $2 "-" $3 "-" $4 "-" $5 "-" $6 "-" $7 "-" $8 "-" $9; split(show,shows,"_"); l = length(shows[1]) } { print substr(shows[1], 0, (l/2))}' )
SAYLASTSHOW5=$( echo $LASTSHOW5 | awk '{ show = $1 "-" $2 "-" $3 "-" $4 "-" $5 "-" $6 "-" $7 "-" $8 "-" $9; split(show,shows,"_"); l = length(shows[1]) } { print substr(shows[1], 0, (l/2))}' )
echo "$SAYLASTSHOW1"
echo "$SAYLASTSHOW2"
echo "$SAYLASTSHOW3"
echo "$SAYLASTSHOW4"
echo "$SAYLASTSHOW5"
if [ ! $SAYLASTSHOW1 = "----" ]; then
SAYLASTSHOW1="While you were away I recorded $SAYLASTSHOW1"
fi
if [ ! $SAYLASTSHOW2 = "----" ]; then
SAYLASTSHOW2="and $SAYLASTSHOW2"
fi
if [ ! $SAYLASTSHOW3 = "----" ]; then
SAYLASTSHOW3="and $SAYLASTSHOW3"
fi
if [ ! $SAYLASTSHOW4 = "----" ]; then
SAYLASTSHOW4="and $SAYLASTSHOW4"
fi
if [ ! $SAYLASTSHOW5 = "----" ]; then
SAYLASTSHOW5="and $SAYLASTSHOW5"
fi
NOWSTATUS=none
echo "Last status: $LASTSTATUS"
echo "Last away date: $AWAYDATE"
echo "Last home date: $HOMEDATE"
# unquote this for testing
# LASTSTATUS=away
# check presence
if hcitool con | grep -q "00:0E:07:E8:07:7E"
then
if [ $LASTSTATUS = away ]; then
echo "home" > /opt/btp/where
echo $(date) > /opt/btp/homedate
echo "$(date) HOME" >> /opt/btp/tracking
NOWSTATUS=home
fi
else
if [ $LASTSTATUS = home ]; then
echo "away" > /opt/btp/where
echo $(date) > /opt/btp/awaydate
echo "$(date) AWAY" >> /opt/btp/tracking
NOWSTATUS=away
fi
fi
# now home event
if [ $NOWSTATUS = home ]; then
# calculate away time
(( ss = `date +%s` - `date -u --date "$AWAYDATE" +%s`))
(( mm = ss / 60 ))
(( ss = ss % 60 ))
(( hh = mm / 60 ))
(( mm = mm % 60 ))
if [ $hh -gt 0 ]; then
SAYHH="$hh hour"
fi
if [ $hh -gt 1 ]; then
SAYHH="$hh hours"
fi
if [ $hh -gt 0 ] && [ $mm -gt 0 ]; then
SAYANDMIN="and"
fi
if [ $mm -gt 0 ]; then
SAYMM="$mm minute"
fi
if [ $mm -gt 1 ]; then
SAYMM="$mm minutes"
fi
# reset recorded shows
echo "[recordings]" > /mnt/btp/recordings.txt
echo "You have been away from home for $SAYHH $SAYANDMIN $SAYMM"
if [ $hh = 0 ] && [ $mm -lt 16 ]; then
echo "Less than 15 minutes or less away, no voice annoucement"
else
echo "Welcome home Anthony. You have been away from home for $SAYHH $SAYANDMIN $SAYMM. $SAYLASTSHOW1 $SAYLASTSHOW2 $SAYLASTSHOW3 $SAYLASTSHOW4 $SAYLASTSHOW5." | festival --tts
fi
fi
# now away event
if [ $NOWSTATUS = away ]; then
echo "Anthony is now away"
fi
if [ $NOWSTATUS = none ]; then
echo "No change in Anthony's presence"
fi
Obviously, this assumes you have already installed Festival, correctly configured your appropriate default ALSA sound device, configured Bluetooth, enabled Bluetooth on your phone, obtainied the MAC address of your phone, and well.. have Linux. I have yet to find a good way of doing a Bluetooth device scan in Windows, but it's a trivial task in Linux. This is not meant to be an exhaustive step-by-step on getting you running, but will be of interest to some I guess. Cool never the less.
The result is when you walk in the door and your Bluetooth phone is automatically detected, you get a nice voice telling you what has been recorded while you were out. A similar approach under Windows would require you to manually connect to the device by right clicking on the device in your Bluetooth manager.
I finally got around to also linking presence to GBPVR. In PostProcessing.bat I added:
echo %1 >> c:\btp\recordings.txt
(the >> appends)
check.sh runs on my linux box and does the following:
#!/bin/sh
# grep for my phone
/usr/bin/hcitool con | grep -q "00:0E:07:E8:07:7E" || (hcitool scan | grep "00:0E:07:E8:07:7E" && hcitool cc 00:0E:07:E8:07:7E )
I created a Windows Share on my GBPVR machine and then mount that share using Samba (also in check.sh):
mount -t smbfs //anya/btp /mnt/btp -o username=foo,password=bar
check.sh maintains my status in where, awaydate and homedate:
# get last status
exec 6<&0
exec < /opt/btp/where
read a1
LASTSTATUS=$a1
exec 0<&6 6<&-
# get last status
exec 5<&0
exec < /opt/btp/homedate
read a1
HOMEDATE=$a1
exec 0<&5 5<&-
# get away date
exec 7<&0
exec < /opt/btp/awaydate
read a1
AWAYDATE=$a1
exec 0<&7 7<&-
# get last recorded shows
exec 4<&0
exec < /mnt/btp/recordings.txt
read a1
read a2
read a3
read a4
read a5
read a6
LASTSHOW1=$a2
LASTSHOW2=$a3
LASTSHOW3=$a4
LASTSHOW4=$a5
LASTSHOW5=$a6
exec 0<&4 4<&-
# parse out the path
echo "Last 5 recorded shows:"
LASTSHOW1=${LASTSHOW1/\"C:recordings/}
LASTSHOW2=${LASTSHOW2/\"C:recordings/}
LASTSHOW3=${LASTSHOW3/\"C:recordings/}
LASTSHOW4=${LASTSHOW4/\"C:recordings/}
LASTSHOW5=${LASTSHOW5/\"C:recordings/}
# extract the directory for the show name announcement
SAYLASTSHOW1=$( echo $LASTSHOW1 | awk '{ show = $1 "-" $2 "-" $3 "-" $4 "-" $5 "-" $6 "-" $7 "-" $8 "-" $9; split(show,shows,"_"); l = length(shows[1]) } { print substr(shows[1], 0, (l/2))}' )
SAYLASTSHOW2=$( echo $LASTSHOW2 | awk '{ show = $1 "-" $2 "-" $3 "-" $4 "-" $5 "-" $6 "-" $7 "-" $8 "-" $9; split(show,shows,"_"); l = length(shows[1]) } { print substr(shows[1], 0, (l/2))}' )
SAYLASTSHOW3=$( echo $LASTSHOW3 | awk '{ show = $1 "-" $2 "-" $3 "-" $4 "-" $5 "-" $6 "-" $7 "-" $8 "-" $9; split(show,shows,"_"); l = length(shows[1]) } { print substr(shows[1], 0, (l/2))}' )
SAYLASTSHOW4=$( echo $LASTSHOW4 | awk '{ show = $1 "-" $2 "-" $3 "-" $4 "-" $5 "-" $6 "-" $7 "-" $8 "-" $9; split(show,shows,"_"); l = length(shows[1]) } { print substr(shows[1], 0, (l/2))}' )
SAYLASTSHOW5=$( echo $LASTSHOW5 | awk '{ show = $1 "-" $2 "-" $3 "-" $4 "-" $5 "-" $6 "-" $7 "-" $8 "-" $9; split(show,shows,"_"); l = length(shows[1]) } { print substr(shows[1], 0, (l/2))}' )
echo "$SAYLASTSHOW1"
echo "$SAYLASTSHOW2"
echo "$SAYLASTSHOW3"
echo "$SAYLASTSHOW4"
echo "$SAYLASTSHOW5"
if [ ! $SAYLASTSHOW1 = "----" ]; then
SAYLASTSHOW1="While you were away I recorded $SAYLASTSHOW1"
fi
if [ ! $SAYLASTSHOW2 = "----" ]; then
SAYLASTSHOW2="and $SAYLASTSHOW2"
fi
if [ ! $SAYLASTSHOW3 = "----" ]; then
SAYLASTSHOW3="and $SAYLASTSHOW3"
fi
if [ ! $SAYLASTSHOW4 = "----" ]; then
SAYLASTSHOW4="and $SAYLASTSHOW4"
fi
if [ ! $SAYLASTSHOW5 = "----" ]; then
SAYLASTSHOW5="and $SAYLASTSHOW5"
fi
NOWSTATUS=none
echo "Last status: $LASTSTATUS"
echo "Last away date: $AWAYDATE"
echo "Last home date: $HOMEDATE"
# unquote this for testing
# LASTSTATUS=away
# check presence
if hcitool con | grep -q "00:0E:07:E8:07:7E"
then
if [ $LASTSTATUS = away ]; then
echo "home" > /opt/btp/where
echo $(date) > /opt/btp/homedate
echo "$(date) HOME" >> /opt/btp/tracking
NOWSTATUS=home
fi
else
if [ $LASTSTATUS = home ]; then
echo "away" > /opt/btp/where
echo $(date) > /opt/btp/awaydate
echo "$(date) AWAY" >> /opt/btp/tracking
NOWSTATUS=away
fi
fi
# now home event
if [ $NOWSTATUS = home ]; then
# calculate away time
(( ss = `date +%s` - `date -u --date "$AWAYDATE" +%s`))
(( mm = ss / 60 ))
(( ss = ss % 60 ))
(( hh = mm / 60 ))
(( mm = mm % 60 ))
if [ $hh -gt 0 ]; then
SAYHH="$hh hour"
fi
if [ $hh -gt 1 ]; then
SAYHH="$hh hours"
fi
if [ $hh -gt 0 ] && [ $mm -gt 0 ]; then
SAYANDMIN="and"
fi
if [ $mm -gt 0 ]; then
SAYMM="$mm minute"
fi
if [ $mm -gt 1 ]; then
SAYMM="$mm minutes"
fi
# reset recorded shows
echo "[recordings]" > /mnt/btp/recordings.txt
echo "You have been away from home for $SAYHH $SAYANDMIN $SAYMM"
if [ $hh = 0 ] && [ $mm -lt 16 ]; then
echo "Less than 15 minutes or less away, no voice annoucement"
else
echo "Welcome home Anthony. You have been away from home for $SAYHH $SAYANDMIN $SAYMM. $SAYLASTSHOW1 $SAYLASTSHOW2 $SAYLASTSHOW3 $SAYLASTSHOW4 $SAYLASTSHOW5." | festival --tts
fi
fi
# now away event
if [ $NOWSTATUS = away ]; then
echo "Anthony is now away"
fi
if [ $NOWSTATUS = none ]; then
echo "No change in Anthony's presence"
fi
Obviously, this assumes you have already installed Festival, correctly configured your appropriate default ALSA sound device, configured Bluetooth, enabled Bluetooth on your phone, obtainied the MAC address of your phone, and well.. have Linux. I have yet to find a good way of doing a Bluetooth device scan in Windows, but it's a trivial task in Linux. This is not meant to be an exhaustive step-by-step on getting you running, but will be of interest to some I guess. Cool never the less.
The result is when you walk in the door and your Bluetooth phone is automatically detected, you get a nice voice telling you what has been recorded while you were out. A similar approach under Windows would require you to manually connect to the device by right clicking on the device in your Bluetooth manager.
SkyPVR & Dedicated HTPC
Shuttle SN45GV3 AMD Sempron 3000+
1GB Dual DDR400 RAM 600GB HD
ATI Radeon 9200SE 128MB (TV out)
Hauppauge PVR-350 PCI
RedRat3 USB Infrared Controller
Pace 430-N Sky Digibox
JS Technology RGB to S-Video Converter, Active VIDEO Buffer & Master SCART Controller
ShinyBox S-Video Splitter
Nikkai gold interconnects
FreeViewPVR & Primary Workstation
Shuttle SN95G5 AMD Athlon64 3500+
2GB Dual DDR400 RAM 450GB HD
MSI GeForce 6800GT 256MB
Hauppauge Nova-T-USB2
Shuttle SN45GV3 AMD Sempron 3000+
1GB Dual DDR400 RAM 600GB HD
ATI Radeon 9200SE 128MB (TV out)
Hauppauge PVR-350 PCI
RedRat3 USB Infrared Controller
Pace 430-N Sky Digibox
JS Technology RGB to S-Video Converter, Active VIDEO Buffer & Master SCART Controller
ShinyBox S-Video Splitter
Nikkai gold interconnects
FreeViewPVR & Primary Workstation
Shuttle SN95G5 AMD Athlon64 3500+
2GB Dual DDR400 RAM 450GB HD
MSI GeForce 6800GT 256MB
Hauppauge Nova-T-USB2