Hi Scott,
I defined BT / iBeacon Items (for presence detection). And the Items run the specific scripts.
Switch BT_JvB “Jeroen’s mobile” (Btpresence) {exec=“<[/scripts/scan_btdev.sh 1:30000:REGEX((.?))]"}
Switch BT_BMW “Jeroen’s car " (Btpresence) {exec=”<[/scripts/scan_ibeacon3.sh 1:20000:REGEX((.?))]”}
Inside the scripts the Linux tools (hcidump / tool …) is used. Script below FYI (quickly put it together it for own use)
!/bin/bash
iBeacon Scan / Jeroen / Nov 2015
$1 = parse → parse is used by the script itself / normally not by the end-user
$2 = -b → output is raw, no explanation
$2 = -uuid → BT address expexted in $3
$3 = (when -uuid is used)
List of iBeacons which you want to scan for
case $1 in
1) UUID=“E2C56DB5-DFFB-48D2-B060-D0F5A71096E0”;;
2) UUID=“FDA50693-A4E2-4FB1-AFCF-C6EB07647825”;;
esac
output=$( sudo hcidump --raw | /scripts/scan_ibeacon.sh parse -uuid $UUID -t 6 )
if [[ $output == “ON” ]]; then
echo “ON”
else
echo “OFF”
fi
The script which is used inside (scan_ibeacon.sh) was developed by Radius Networks. Changed it a bit for usage at home (when you want the original just google)
if [ ! “$(pidof hcitool)” ]; then
sudo hcitool lescan --duplicates 1>/dev/null &
fi
if [[ $1 == “parse” ]]; then
packet=“”
capturing=“”
count=0
now=date +%s
if [[ $4 == “-t” ]]; then
finish=$((now+$5))
else
finish=$((now+300))
fi
while read line && [[ “$now” -lt “$finish” ]]
do
count=$[count + 1]
now=date +%s
if [ “$capturing” ]; then
if [[ $line =~ {2}\ [0-9a-fA-F] ]]; then
packet=“$packet $line”
else
if [[ $packet =~ ^04\ 3E\ 2A\ 02\ 01\ .{26}\ 02\ 01\ .{14}\ 02\ 15 ]]; then
UUID=echo $packet | sed 's/^.\{69\}\(.\{47\}\).*$/\1/'
MAJOR=echo $packet | sed 's/^.\{117\}\(.\{5\}\).*$/\1/'
MINOR=echo $packet | sed 's/^.\{123\}\(.\{5\}\).*$/\1/'
POWER=echo $packet | sed 's/^.\{129\}\(.\{2\}\).*$/\1/'
UUID=echo $UUID | sed -e 's/\ //g' -e 's/^\(.\{8\}\)\(.\{4\}\)\(.\{4\}\)\(.\{4\}\)\(.\{12\}\)$/\1-\2-\3-\4-\5/'
MAJOR=echo $MAJOR | sed 's/\ //g'
MAJOR=echo "ibase=16; $MAJOR" | bc
MINOR=echo $MINOR | sed 's/\ //g'
MINOR=echo "ibase=16; $MINOR" | bc
POWER=echo "ibase=16; $POWER" | bc
POWER=$[POWER - 256]
RSSI=echo $packet | sed 's/^.\{132\}\(.\{2\}\).*$/\1/'
RSSI=echo "ibase=16; $RSSI" | bc
RSSI=$[RSSI - 256]
if [[ $2 == "-b" ]]; then
echo "$UUID $MAJOR $MINOR $POWER $RSSI"
elif [[ $2 == "-uuid" ]]; then
if [[ $UUID == $3 ]]; then
echo "ON"
break;
fi
fi
fi
capturing=""
packet=""
fi
fi
if [ ! "$capturing" ]; then
if [[ $line =~ ^\> ]]; then
packet=`echo $line | sed 's/^>.\(.*$\)/\1/'`
capturing=1
fi
fi
done
Below a script for Bluetooth
!/bin/bash
Script to ping BT addresses on layer 2
List of known MAC addresses are provided
The device does NOT necessarily need to be scanning for other devices as this is a layer 2 ping.
Layer 2 ping does not work for (i)Beacon) - use “hcitool lescan” instead
case $1 in
1) MAC=“00:EE:BD:55:F1:BA”;;
2) MAC=“00:0E:9F:F2:D0:67”;;
3) MAC=“74:E1:B6:8D:FE:81”;;
esac
if l2ping -c 1 $MAC &> /dev/null
then
echo “ON”
else
echo “OFF”
fi
Hope it helps
Chrs - Jeroen