42 iBeacon Detector

V0.0.1

42.1 Histroy

  • 2014-12-02, rayoslee, release V0.0.1

42.2 FAQ

  1. How to use iBeacon Detector in S605 ?

    • ./iBeaconDetector.sh hci0 or ./iBeaconDetector.sh hci0 -raw
  2. iBeacon Detector is bash file, it is scripted as following

    if [[ $2 == "parse" ]]; then
        packet=""
        catch=""
        count=0
        while read row
        do
          count=`echo "$count+1" | bc`
          if [ "$catch" ]; then
    
            if [[ $row =~ ^[0-9a-fA-F]{2}\ [0-9a-fA-F] ]]; then    
              packet="$packet $row"    
            else
    
              if [[ $packet =~ ^04\ 3E\ 2B\ 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=`echo "$POWER-256" | bc`
                if [[ $3 == "-raw" ]]; then
                  echo "$UUID $MAJOR $MINOR $POWER"
                else
                  echo "UUID) $UUID MAJOR) $MAJOR MINOR) $MINOR POWER) $POWER"
                fi
              fi
              catch=""
              packet=""
            fi
          fi
    
          if [ ! "$catch" ]; then
            if [[ $row =~ ^\> ]]; then
              packet=`echo $row | sed 's/^>.\(.*$\)/\1/'`
              catch=1
            fi
          fi
        done
    else
      hcitool -i $1 lescan 1>/dev/null &
      if [ "$(pidof hcitool)" ]; then
       hcidump -i $1 --raw | ./$0 $1 parse $2
      fi
    fi