Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

James Robertson http://www.r0bertson.co.uk

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Using Ruby to detect Bluetooth proximity

This Ruby script uses the hcitool and rfcomm to detect the proximity of a bluetooth enabled mobile phone. The signal strength in this script will return a value from 0 to 10, 0 is near and 10 is far, otherwise if there is no connection it will keep on trying.

deviceid = '00:12:D1:E6:57:BE' 
range = ''
count = 0
while count < 1
  # assuming the bt device is already connected get the signal strength value.
  range = `hcitool rssi #{deviceid}`.chomp
  if  range.length > 0
    puts range[/\w+$/]
  else
    puts 'connecting to the bluetooth device ...'
    Thread.new{`rfcomm connect 0 #{deviceid}`}
  end
	
  sleep 7
end

Simple Bluetooth Proximity

Following on from my earlier investigation into bluetooth proximity, I wanted something which returned a value which could be used to determine distance. The output from hcitool rssi ranges from 0 for close object down to -10 for far away objects.

rfcomm connect 0 00:12:D1:E6:57:BE

hcitool rssi 00:12:D1:E6:57:BE


Proximity Results:
-4 .. 0 : Bedroom - nearest to my bed
-4 .. -6 : Hallway
-8 .. -9 : Livingroom - on the computer desk
-9 .. -10 : Livingroom - nearest to the window
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS