How to use the noble.on function in noble

To help you get started, we’ve selected a few noble examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jmaxxz / keymaker / node_tools / src / lib / lock_scanner.js View on Github external
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;
      }
github demirhanaydin / node-mi-flora / index.js View on Github external
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);
        }
      });
    }
  }
github peterlee0127 / YeeLight-Blue-2 / ble.js View on Github external
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;
github jacopotagliabue / anki-drive-python-sdk / node_app / node_socket_app / node_server.js View on Github external
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);
    }
});
github saphero / sphero-hack / setup / setup-bb8.js View on Github external
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 {
github new-davinci / node-flexbot / lib / flexbot.js View on Github external
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];
github paolotremadio / homebridge-automation-bluetooth-presence / index.js View on Github external
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);
  }
github demirhanaydin / node-mi-flora / index.js View on Github external
constructor(macAddress) {
    super();
    this.noble = noble;
    this._macAddress = macAddress;
    noble.on('discover', this.discover.bind(this));
  }
github Azure / iotedge / edge-modules / edge-ble / src / sensormanager.ts View on Github external
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);
  }
github maxogden / ble-stream / central.js View on Github external
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
}

noble

A Node.js BLE (Bluetooth Low Energy) central library.

MIT
Latest version published 6 years ago

Package Health Score

33 / 100
Full package analysis

Popular noble functions