Created
October 28, 2015 10:07
-
-
Save c0ze/0f02d46b82fa375589ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Eddystone Scan by Arda Karaduman | |
# Based on ibeacon_scan by radius networks | |
# http://stackoverflow.com/questions/21733228/can-raspberrypi-with-ble-dongle-detect-ibeacons | |
if [[ $1 == "parse" ]]; then | |
packet="" | |
capturing="" | |
count=0 | |
while read line | |
do | |
count=$[count + 1] | |
if [ "$capturing" ]; then | |
if [[ $line =~ ^[0-9a-fA-F]{2}\ [0-9a-fA-F] ]]; then | |
packet="$packet $line" | |
else | |
if [[ $packet =~ ^04\ 3E\ .{2}\ 02\ 01\ .{26}\ 02\ 01\ .{12} ]]; then | |
# printf "$packet\n" | |
TYPE=`echo $packet | sed 's/^.\{75\}\(.\{2\}\).*$/\1/'` | |
POWER=`echo $packet | sed 's/^.\{78\}\(.\{2\}\).*$/\1/'` | |
POWER=`echo "ibase=16; $POWER" | bc` | |
POWER=$[POWER - 256] | |
LEN=$[${#packet} - 2] | |
RSSI=`echo $packet | sed "s/^.\{$LEN\}\(.\{2\}\).*$/\1/"` | |
RSSI=`echo "ibase=16; $RSSI" | bc` | |
RSSI=$[RSSI - 256] | |
case "$TYPE" in | |
00) | |
TYPE=UID | |
UUID=`echo $packet | sed 's/^.\{81\}\(.\{30\}\).*$/\1/'` | |
INSTANCE=`echo $packet | sed 's/^.\{111\}\(.\{18\}\).*$/\1/'` | |
echo "TYPE : $TYPE UUID : $UUID INSTANCE : $INSTANCE POWER : $POWER RSSI : $RSSI" | |
;; | |
10) | |
TYPE=URL | |
SCHEME=`echo $packet | sed 's/^.\{81\}\(.\{2\}\).*$/\1/'` | |
LEN=$[${#packet} - 86] | |
URL=`echo $packet | sed "s/^.\{83\}\(.\{$LEN\}\).*$/\1/"` | |
URL=`echo $URL | sed 's/ /\\\x/g'` | |
URL="\\x$URL" | |
URL=`echo -e $URL | awk '{printf "%s\n", $_}'` | |
echo "TYPE : $TYPE SCHEME : $SCHEME URL : $URL POWER : $POWER RSSI : $RSSI" | |
;; | |
20) | |
TYPE=TLM | |
VERSION=`echo $packet | sed 's/^.\{78\}\(.\{2\}\).*$/\1/'` | |
BATTERY=`echo $packet | sed 's/^.\{81\}\(.\{5\}\).*$/\1/' | sed 's/ //g'` | |
BATTERY=`echo "ibase=16; $BATTERY" | bc` | |
TEMP=`echo $packet | sed 's/^.\{87\}\(.\{5\}\).*$/\1/' | sed 's/ //g'` | |
TEMP=`echo "ibase=16; $TEMP" | bc` | |
TEMP=`bc <<< "scale=2; $TEMP/256"` | |
PCOUNT=`echo $packet | sed 's/^.\{93\}\(.\{11\}\).*$/\1/' | sed 's/ //g'` | |
PCOUNT=`echo "ibase=16; $PCOUNT" | bc` | |
TIME=`echo $packet | sed 's/^.\{105\}\(.\{11\}\).*$/\1/' | sed 's/ //g'` | |
TIME=`echo "ibase=16; $TIME" | bc` | |
echo "TYPE : $TYPE VERSION : $VERSION BATTERY : $BATTERY TEMP : $TEMP PCOUNT : $PCOUNT TIME : $TIME RSSI : $RSSI" | |
;; | |
esac | |
fi | |
capturing="" | |
packet="" | |
fi | |
fi | |
if [ ! "$capturing" ]; then | |
if [[ $line =~ ^\> ]]; then | |
packet=`echo $line | sed 's/^>.\(.*$\)/\1/'` | |
capturing=1 | |
fi | |
fi | |
done | |
else | |
sudo hcitool lescan --duplicates 1>/dev/null & | |
if [ "$(pidof hcitool)" ]; then | |
sudo hcidump --raw hci | ./$0 parse $1 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment