Skip to content

Instantly share code, notes, and snippets.

@taka-wang
Forked from maciej/scan-beacons.js
Last active August 29, 2015 14:12
Show Gist options
  • Save taka-wang/915f403e3b969ae7f57c to your computer and use it in GitHub Desktop.
Save taka-wang/915f403e3b969ae7f57c to your computer and use it in GitHub Desktop.
// Requires NodeJS and "noble" module: https://github.com/sandeepmistry/noble
// Based on: https://github.com/sandeepmistry/noble/issues/62
var noble = require('noble');
noble.on('stateChange', function(state) {
if (state === 'poweredOn' ) {
noble.startScanning([], false);
} else {
noble.stopScanning();
}
});
noble.on('discover', function(peripheral) {
peripheral.connect(function(error) {});
peripheral.on('connect',function(){});
peripheral.on('rssiUpdate',function(rssi){
console.log({"uuid": peripheral.uuid, "rssi": peripheral.rssi });
});
setInterval(function(){
peripheral.updateRssi();
}, 100);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment