Пример #1
0
noble.on('stateChange', function(state) {
    if (state === 'poweredOn') {
        noble.stopScanning();
        noble.startScanning();
    } else {
        noble.stopScanning();
    }
});
  noble.on('discover', function(peripheral) {
    // we found a peripheral, stop scanning
    noble.stopScanning();

    //
    // The advertisment data contains a name, power level (if available),
    // certain advertised service uuids, as well as manufacturer data,
    // which could be formatted as an iBeacon.
    //
    console.log('-------- peripheral uuid:', peripheral.uuid);
    console.log('found peripheral:', peripheral.advertisement);
    //
    // Once the peripheral has been discovered, then connect to it.
    // It can also be constructed if the uuid is already known.
    ///
    peripheral.connect(function(err) {
      //
      // Once the peripheral has been connected, then discover the
      // services and characteristics of interest.
      //
      peripheral.discoverServices([], function(err, services) {
        services.forEach(function(service) {
          //
          // This must be the service we were looking for.
          //
          console.log('found service:', service.uuid);

        })
      })
    })
  })
Пример #3
0
    peripheral.connect();       // start connection attempts

    // the connect function. This is local to the discovery function
    // because it needs to know the peripheral to discover services:
    function discover() {
      // once you know you have a peripheral with the desired
      // service, you can stop scanning for others:
      noble.stopScanning();
      // get the service you want on this peripheral:
      peripheral.discoverServices([serviceUUID],explore);
    }
Пример #4
0
noble.on('stateChange', (state) => {
  if (state === 'poweredOn') {
    noble.startScanning();
  } else {
    noble.stopScanning();
  }
});
Пример #5
0
	this.ddbstateChange = function( state ){
	  if (state === 'poweredOn') {
		  noble.startScanning();
	  } else {
		  noble.stopScanning();
	  }	
	}
Пример #6
0
 setTimeout(function() {
   noble.stopScanning();
   if (discovered == false) {
     console.log('No Dash discovered. Make sure sensor data is sent by pressing the left Dash for 5 seconds');
     process.exit(0);
   }
 }, 3000);
Пример #7
0
BlePeripherals.prototype._handleStateChanges = function(state){
	if(state === 'poweredOn'){
		noble.startScanning();
	}else{
		noble.stopScanning();
	}
};
Пример #8
0
BleProfiler.prototype.discoverDevice = function(peripheral) {
  if (peripheral.address.toLowerCase() === this.target.toLowerCase()) {
    /* Stop scanning. */
    noble.stopScanning();

    /* Try to connect to our device, and explore services. */
    this.currentDevice = peripheral;
    this.services = 0;
    this.characteristics = 0;

    peripheral.connect(function(error) {
      if (error == undefined) {
        if (!this.devices[this.currentDevice.address].connected) {
          console.log('Target detected in range, starting profiling ...'.bold);
          this.devices[this.currentDevice.address].connected = true;
          this.devices[this.currentDevice.address].name = peripheral.advertisement.localName;
          this.onDeviceConnected(this.currentDevice);
        }
      } else {
        this.onDiscoverFailed();
      }
    }.bind(this));

  }
};
Пример #9
0
var stopandreturn = function (){
    noble.stopScanning();
    noble.removeListener('discover', discover);
    console.log('Stop Scanning for BLE devices...');

    this.done(this.peripherals);
};
Пример #10
0
 noble.on('stateChange', function(state) {
   if (state === 'poweredOn'){
     noble.startScanning([self.serviceId], false);
   }else{
     noble.stopScanning();
   }
 });
Пример #11
0
 _onStateChange: function(state) {
   if (state === 'poweredOn') {
     noble.startScanning(["180d"]);
   } else {
     noble.stopScanning();
   }
 },
Пример #12
0
					iphone.discoverServices([serviceUUID], function(error, services) {
						console.log(services.length + ' services found')

						if (services.length > 0) {
							noble.stopScanning();

							var batteryService = services[0];
							console.log('Discovered Context Data service');

							batteryService.discoverCharacteristics([characteristicUUID], function(error, characteristics) {
								batteryLevelCharacteristic = characteristics[0];
								console.log('Discovered Context Data characteristic');

								batteryLevelCharacteristic.on('read', function(data, isNotification) {
									var now = moment();
									var formatted = now.format('YYYY-MM-DD HH:mm:ss:SSS');
									// console.log('received from '+peripheral.uuid+': '+ data.toString('hex'));
									console.log('['+formatted+'] received from '+peripheral.uuid+': '+ data.toString('hex'));
								});

								batteryLevelCharacteristic.subscribe(function(err){
									if (err) {
										console.log(err);
									} else {
										console.log('Context data notification is now on');
									}
								});
							});
						}
					});
Пример #13
0
function exitHandler(options, err) {
  logData("Event", "System", "Shutting down.");
  noble.stopScanning();
  logFileUpdate(function() {
    process.exit();
  });
}
Пример #14
0
 noble.on('discover', function(p){
   if (p.advertisement.localName && p.advertisement.localName.startsWith("SHL")) {
     peripheral = p;
     noble.stopScanning();
     console.log("Found device.")
   }
 });
Пример #15
0
	noble.on('discover', function(peripheral) {
		if(peripheral.advertisement.localName === 'Crazyflie'){
			noble.stopScanning();
			_this.peripheral = peripheral;
			console.log('Crazyflie with UUID ' + peripheral.uuid + ' found');

			_this.peripheral.on('disconnect', function() { process.exit(0); });

			_this.peripheral.on('rssiUpdate', function() { console.log(peripheral.rssi); });

			_this.peripheral.connect(function(error) {
				if(error) {
					console.log(error);
					return _this.callback(error, null);
					// process.exit(0); // Allows users to handle failed connection
				}
				else {
					_this.connected = true;
					console.log('Connected to Crazyflie');
					_this.peripheral.discoverServices(SERVICE_UUID, function(error, services) {
						_this.service = services[0];
						_this.service.discoverCharacteristics(CHARACTERISTIC_UUID, function(error, characteristics) {
							_this.characteristic = characteristics[0];
								_this.callback(null, _this);
						});
					});
				}
			});
		}
	});
Пример #16
0
.on('discover', function (peripheral) {
    console.log('discover >>> Found device with UUID: ' + peripheral.uuid);
    console.log('discover >>> and local name: ' + peripheral.advertisement.localName);
    console.log('discover >>> advertising the following service uuid\'s: ' + peripheral.advertisement.serviceUuids);

    if (opts.verbose) {
        console.log('discover >>> ' + peripheral);
    }

    if (opts.listen && opts.listen === peripheral.uuid) {

        noble.stopScanning();

        // Bind callback to RSSI update
        console.info('discover >>> Listening for RSSI change');
        peripheral.on('rssiUpdate', function (rssi) {
            console.log('rssiUpdate >>> ' + peripheral.uuid + ' >>> ' + rssi);
        });

        peripheral.connect(function (err) {

            if (err) {
                console.error('connect xxx ' + err);
                return;
            }

            setInterval(function () {
                console.log('rssiUpdate >>> peripheral.updateRssi');
                peripheral.updateRssi();
            }, 1000);
        });

    }
});
noble.on('stateChange',function(state){
	if(state == 'poweredOn'){
		console.log("Bluetooth stateChange, start scanning...");
		noble.startScanning([],true);
	}else{
		noble.stopScanning();
	}
});
Пример #18
0
noble.on('stateChange', function(state) {
    if (state === 'poweredOn') {
        noble.startScanning(['bbb0']);
    } else {
        noble.stopScanning();
        alert('Please enable Bluetooth');
    }
});
Пример #19
0
noble.on('discover', function(peripheral) {
  if (peripheral.uuid === peripheralUuid) {
    console.log("found light bulb!");
      noble.stopScanning();
      console.log('matching services and characteristics...');
    lightupPeripheral = peripheral;
    }
});
Пример #20
0
noble.on('stateChange', function (state) {
  console.log('state change', state);
  if (state === 'poweredOn') {
    noble.startScanning();
  } else {
    noble.stopScanning();
  }
});
Пример #21
0
noble.on('stateChange', function(state) {
  if (state === 'poweredOn') {
    noble.startScanning();
    console.log('Searching for Angel Sensor')
  } else {
    noble.stopScanning();
  }
});
 noble.on('stateChange', function(state) {
   if (state === 'poweredOn') {
     noble.startScanning(deviceClass.SCAN_UUIDS | [], this.SCAN_DUPLICATES);
   } else {
     noble.stopScanning();
     reject('bluetooth off?');
   }
 });
Пример #23
0
noble.on('stateChange', function(state) {
    if (state === 'poweredOn') {
        console.log("Starting scan...");
        noble.startScanning([], true);
    } else {
        noble.stopScanning();
    }
});
 noble.on('discover', (peripheral) => {
   let deviceClass = deviceClasses.find(devCls => devCls.is(peripheral));
   devices.push(new deviceClass(peripheral));
   if(devices.length == deviceClasses.length) {
     noble.stopScanning();
     resolve(devices);
   }
 });
Пример #25
0
noble.on('stateChange', function(state) {
  if (state === 'poweredOn') {
    scan();
  } else {
    debug('scan', 'stop scanning ... ');
    noble.stopScanning();
  }
});
Пример #26
0
process.stdin.resume();//so the program will not close instantly
function exitHandler(options, err) {
    console.log('stopScanning & exit');
    if (currentPeripheral != null){
    	currentPeripheral.disconnect();
	}
    noble.stopScanning();
    process.exit();
}
 noble.on('stateChange', function(state) {
   if (state === 'poweredOn') {
     noble.startScanning(SCAN_UUIDS, false);
   } else {
     noble.stopScanning();
     reject('bluetooth fff?');
   }
 });
Пример #28
0
 // the connect function. This is local to the discovery function
 // because it needs the peripheral to discover services:
 function connectMe() {
   noble.stopScanning();
   console.log('Checking for services on ' + peripheral.advertisement.localName);
   // start discovering services:
   // you could also use peripheral.discoverSomeServicesAndCharacteristics here,
   // and filter by the target service and characteristic:
   peripheral.discoverAllServicesAndCharacteristics(exploreMe);
 }
Пример #29
0
 noble.on('discover', function(peripheral) {
     if (peripheral.id == sensorId) {
         console.log('Found sensor');
         noble.stopScanning();
         var sensor = new PolarH7(peripheral);
         callback(sensor);
     }
 });
Пример #30
0
noble.on('stateChange', function(state) {
  if (state === 'poweredOn') {
    noble.startScanning();
  } else {
    console.log('Stopped scanning');
    noble.stopScanning();
  }
});