Detect of bluetooth devices get in or out of reach with l2ping
and node.js
npm install btwatch
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
Sets the search parameters.
Start watching specified mac address.
End watching specified mac address.
Check and return if specified mac address is in reach.
Called if any of watched mac address changes its reach.
Called if any of watched mac address changes its reach, but returns all watched mac address states.
Called if watched mac address specifiedMacAddress changes its reach.
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);
}
});