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;
}
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];
discoverDevices() {
noble.on('stateChange', (state) => {
if (state === 'poweredOn') {
this.log('Looking for Bluetooth devices');
noble.startScanning([], false);
} else {
noble.stopScanning();
}
});
noble.on('discover', this.deviceDiscovered.bind(this));
setInterval(this.deviceTimer.bind(this), 1000);
}
constructor(macAddress) {
super();
this.noble = noble;
this._macAddress = macAddress;
noble.on('discover', this.discover.bind(this));
}
constructor() {
super();
this.inReset = false;
this.connectedSensors = {};
this.aggregateScanRequests = {};
this.aggregateScanRequests[SensorManager.scanByUUID] = {};
this.aggregateScanRequests[SensorManager.scanByName] = {};
this.scanner = new Scanner();
this.sensorsConfig = new BLESensorsConfiguration();
noble.on('discover', this.onDiscover);
noble.on('disconnect', this.onDisconnect);
}
setTimeout(function () {
ch.read(function (err, data) {
if (err) return cb(err)
if (!data) return cb(null, null)
timeout = data.length === 100 ? 1 : 200
debug('onread', {length: data.length})
cb(null, data)
})
}, timeout)
})
stream.setWritable(input)
stream.setReadable(output)
}
noble.on('stateChange', onchange)
noble.on('discover', ondiscover)
return stream
}