btwatch
v1.1.0
Published
Detect of bluetooth devices get in or out of reach with l2ping and node.js
Downloads
6
Maintainers
Readme
btwatch
Detect of bluetooth devices get in or out of reach with l2ping
and node.js
Instalation
npm install btwatch
Dependencies
Bluetooth library must be installed and turned on:
apt-get install bluez
hciconfig hci0 up
(it can be at cron too:@reboot sudo hciconfig hci0 up
)
And must be paired with watched mac address object:
- find object:
hcitool scan
- pair object:
rfcomm connect 0 <objectMacAddress> 10
Methods
BTWatch.set(maxPingAttempts, maxPingSeconds)
Sets the search parameters.
BTWatch.watch(macAddress)
Start watching specified mac address.
BTWatch.unwatch(macAddress)
End watching specified mac address.
BTWatch.inRange(macAddress)
Check and return if specified mac address is in reach.
BTWatch.on('change', callback(inRange, macAddress))
Called if any of watched mac address changes its reach.
BTWatch.on('change::all', callback(arrayOfMacAddressesStates))
Called if any of watched mac address changes its reach, but returns all watched mac address states.
BTWatch.on('change::specifiedMacAddress', callback(inRange, macAddress))
Called if watched mac address specifiedMacAddress changes its reach.
Example
var BTWatch = require('btwatch');
var objectMacAddr = '00:F7:6F:01:02:03';
if (BTWatch.inRange(objectMacAddr)) {
console.log('Mac address %s is in range', objectMacAddr);
} else {
console.log('Mac address %s isnt in range', objectMacAddr);
}
BTWatch.watch(objectMacAddr);
BTWatch.on('change', function (inRange, macAddress) {
if (inRange) {
console.log('Mac address %s is now in range', objectMacAddr);
} else {
console.log('Mac address %s now leave from range', objectMacAddr);
}
});