#/bin/bash # Script to execute a command when going too far and one when being near enough from the other adapter # When going too far cmd1="rhythmbox-client --pause" # When going too near cmd2="rhythmbox-client --play" # The other endpoint badr="00:19:1D:AB:98:23" # Threshold level lvl="-4" # On startup, if the device is close enough, don't execute anything on=1 smooth=0 while /bin/true do l=`hcitool rssi ${badr} | tail -1 | cut -f 2 -d':'` # echo "Power=$l" if [ "$l" -le $lvl ] && [ $on == 1 ] then if [ $smooth == 2 ] then echo "Too far" ${cmd1} on=0 smooth=0 else echo "Are we too far?" let smooth=smooth+1 fi elif [ "$l" -gt $lvl ] then if [ $on == 0 ] then echo "Near enough" ${cmd2} on=1 else smooth=0 fi fi sleep 3 done