Skip to content

Instantly share code, notes, and snippets.

@miguel-amaral
Last active March 22, 2018 19:59
Show Gist options
  • Save miguel-amaral/585aa5946950be42b8c90a3603d675a0 to your computer and use it in GitHub Desktop.
Save miguel-amaral/585aa5946950be42b8c90a3603d675a0 to your computer and use it in GitHub Desktop.
var blue = require("bluetoothctl");
var sleep = require('sleep');
blue.Bluetooth()
blue.on(blue.bluetoothEvents.Controller, function(controllers){
console.log('Controllers:' + JSON.stringify(controllers,null,2))
});
blue.on(blue.bluetoothEvents.DeviceSignalLevel, function(devices,mac,signal){
console.log('signal level of:' + mac + ' - ' + signal)
});
blue.on(blue.bluetoothEvents.Device, function (devices) {
console.log('devices:' + JSON.stringify(devices,null,2))
})
blue.on(blue.bluetoothEvents.PassKey, function (passkey) {
console.log('Confirm passkey:' + passkey)
blue.confirmPassKey(true);
})
var hasBluetooth=blue.checkBluetoothController();
console.log('system has bluetooth controller:' + hasBluetooth)
if(hasBluetooth) {
blue.power(true)
console.log("power is on")
blue.discoverable(true);
console.log("discoverable is on")
blue.pairable(true);
console.log("pairable is on")
blue.agent(true)
console.log("agent is on")
while (true){
console.log('isBluetooth Ready:' + blue.isBluetoothReady)
sleep.sleep(2)
}
// blue.scan(true)
// setTimeout(function(){
// console.log('stopping scan')
// blue.scan(false)
// blue.info('00:0C:8A:8C:D3:71')
// },20000)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment