Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.start = function start(){
noble.on('stateChange', function(state) {
if (state === 'poweredOn') {
noble.startScanning(["bd4ac6100b4511e38ffd0800200c9a66"], false);
this.emit('start');
} else {
noble.stopScanning();
this.emit('stop');
}
}.bind(this));
noble.on('discover', async peripheral => {
// things seem pretty unstable if one starts looking
// at the peripheral immediately.
await delay(500);
if(!peripheral.advertisement.manufacturerData || peripheral.advertisement.manufacturerData.length < 20) {
return;
}
noble.on('stateChange', function (state) {
if (state === 'poweredOn') {
// Note, tritag *does not* advertise it's service uuid, only eddystone/summon
noble.startScanning(SUMMON_SERVICE_UUIDS, true);
console.log('Started scanning.');
}
});
startScanning() {
if (noble.state === 'poweredOn') {
noble.startScanning([], true);
} else {
// bind event to start scanning
noble.on('stateChange', function (state) {
if (state === 'poweredOn') {
noble.startScanning([], true);
}
});
}
}
function startDiscover(devices){
noble.on('stateChange', function(state) {
if (state === 'poweredOn'){
if(!Array.isArray(devices)) {
console.log("please set startDiscover([])");
process.exit();
}
discover(devices);
}
else{
noble.stopScanning();
}
});
}
exports.startDiscover = startDiscover;
noble.on('stateChange', function(state) {
if (state === 'poweredOn')
{
console.log("powered on!");
noble.on('discover', function(device) {
console.log(util.format("SCAN|%s|%s", device.id, device.address));
});
noble.startScanning(ANKI_DRIVE_SERVICE_UUIDS);
setTimeout(function() {
noble.stopScanning();
console.log("SCAN|COMPLETED");
}, 2500);
}
});
module.exports = exports = (callback) => {
console.log('Beginning setup');
noble.startScanning();
noble.on('discover', (peripheral) => {
if (_.includes(peripheral.advertisement.localName, 'BB-')) {
var deviceUUID = peripheral.uuid;
var localName = peripheral.advertisement.localName;
console.log('Writing to config file');
console.log('BB8 UUID - "' + deviceUUID + '"');
console.log('Local Name: ' + localName);
var config = require('home-config').load('.bb8config', {
BB8_UUID: deviceUUID,
BB8_LOCAL_NAME: localName
});
config.save();
noble.stopScanning();
console.log('Connected to ' + config.BB8_LOCAL_NAME);
console.log('Saved config file to ~/.bb8config');
callback();
} else {
that.connect = function (callback) {
noble.on('discover',function (p) {
if (FLEX_SIGNATURES.indexOf(p.advertisement.localName) >= 0 || p.advertisement.serviceUuids.indexOf('ffe0') >= 0) {
console.log('Discovered a Flexbot.')
that.copter = p;
that.copter.connect(function () {
console.log('Connected to Flexbot.');
noble.stopScanning();
that.copter.discoverServices(['ffe0'], function (error, services) {
if(error){
callback(error);
} else {
services[0].discoverCharacteristics(['ffe1'], function (error, characteristics) {
if(error){
callback(error);
} else {
that.BLECharacteristic = characteristics[0];
await new Promise((resolve, reject) => {
noble.startScanning([ROOT_SERVICE_UUID], true, error => {
if (error) {
return reject(error);
}
return resolve();
});
});
await wait(timeout);
function scan(state){
if (state === 'poweredOn') {
noble.startScanning();
console.log("Started scanning");
} else {
noble.stopScanning();
console.log("Is Bluetooth on?");
}
}
function scan(state){
if (state === 'poweredOn') {
noble.startScanning();
console.log("Started scanning");
} else {
noble.stopScanning();
console.log("Is Bluetooth on?");
}
}