How to use @abandonware/noble - 10 common examples

To help you get started, we’ve selected a few @abandonware/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 thegecko / webbluetooth / src / adapter.ts View on Github external
this.init(() => {
            this.deviceHandles = {};
            function stateCB() {
                if (this.state === true) {
                    // Noble doesn't correctly match short and canonical UUIDs on Linux, so we need to check ourselves
                    // Continually scan to pick up all advertised UUIDs
                    noble.startScanning([], true, this.checkForError(errorFn, completeFn));
                } else {
                    errorFn("adapter not enabled");
                }
            }

            if (noble.state === "unknown" || noble.state === "poweredOff") {
                // tslint:disable-next-line:no-string-literal
                noble["once"]("stateChange", stateCB.bind(this));
            } else {
                stateCB.call(this);
            }
        });
    }
github urish / real-trex-runner / firmware / src / button.js View on Github external
peripheral.once('disconnect', () => {
        console.log('disconnected');
        // Clean noble's peripheral cache
        noble._peripherals = {};
        connectionListener(false);
        scanButton();
      });
    }
github thegecko / webbluetooth / src / adapter.ts View on Github external
this.init(() => {
            this.deviceHandles = {};
            function stateCB() {
                if (this.state === true) {
                    // Noble doesn't correctly match short and canonical UUIDs on Linux, so we need to check ourselves
                    // Continually scan to pick up all advertised UUIDs
                    noble.startScanning([], true, this.checkForError(errorFn, completeFn));
                } else {
                    errorFn("adapter not enabled");
                }
            }

            if (noble.state === "unknown" || noble.state === "poweredOff") {
                // tslint:disable-next-line:no-string-literal
                noble["once"]("stateChange", stateCB.bind(this));
            } else {
                stateCB.call(this);
            }
        });
    }
github icanos / hassio-plejd / plejd / plejd.js View on Github external
async disconnect() {
    logger('disconnecting from Plejd');

    if (this.isConnected) {
      clearInterval(this.pingRef);

      if (this.peripheral) {
        try {
          // disconnect
          await this.peripheral.disconnect();

          // we need to reset the ble adapter too
          noble._bindings._hci.reset();

          // wait 200 ms for reset command to take effect :)
          sleep.msleep(200);

          // now we're ready to connect again
        }
        catch (error) {
          console.log('error: unable to disconnect from Plejd: ' + error);
          return Promise.resolve(false);
        }

        this.isConnected = false;
        logger('disconnected from Plejd');

        return Promise.resolve(true);
      }
github thegecko / webbluetooth / src / adapter.ts View on Github external
function stateCB() {
                if (this.state === true) {
                    // Noble doesn't correctly match short and canonical UUIDs on Linux, so we need to check ourselves
                    // Continually scan to pick up all advertised UUIDs
                    noble.startScanning([], true, this.checkForError(errorFn, completeFn));
                } else {
                    errorFn("adapter not enabled");
                }
            }
github LedgerHQ / ledgerjs / packages / hw-transport-node-ble / src / platform.js View on Github external
export const availability: Observable = Observable.create(observer => {
  const onAvailabilityChanged = e => {
    observer.next(e === POWERED_ON);
  };
  noble.addListener("stateChanged", onAvailabilityChanged); // events lib?
  observer.next(noble.state === POWERED_ON);
  return () => {
    noble.removeListener("stateChanged", onAvailabilityChanged);
  };
});
github LedgerHQ / ledgerjs / packages / hw-transport-node-ble / src / platform.js View on Github external
export const availability: Observable = Observable.create(observer => {
  const onAvailabilityChanged = e => {
    observer.next(e === POWERED_ON);
  };
  noble.addListener("stateChanged", onAvailabilityChanged); // events lib?
  observer.next(noble.state === POWERED_ON);
  return () => {
    noble.removeListener("stateChanged", onAvailabilityChanged);
  };
});
github thegecko / webbluetooth / src / adapter.ts View on Github external
public getEnabled(completeFn: (enabled: boolean) => void) {
        function stateCB() {
            completeFn(this.state);
        }

        if (noble.state === "unknown" || noble.state === "poweredOff") {
            // tslint:disable-next-line:no-string-literal
            noble["once"]("stateChange", stateCB.bind(this));
        } else {
            stateCB.call(this);
        }
    }
github thegecko / webbluetooth / src / adapter.ts View on Github external
public getEnabled(completeFn: (enabled: boolean) => void) {
        function stateCB() {
            completeFn(this.state);
        }

        if (noble.state === "unknown" || noble.state === "poweredOff") {
            // tslint:disable-next-line:no-string-literal
            noble["once"]("stateChange", stateCB.bind(this));
        } else {
            stateCB.call(this);
        }
    }
github urish / real-trex-runner / firmware / src / button.js View on Github external
function init(clickListener, connectionListener = () => 0) {
  noble.on('stateChange', (state) => {
    if (state === 'poweredOn') {
      scanButton();
    } else {
      noble.stopScanning();
    }
  });

  noble.on('discover', (peripheral) => {
    if (peripheral.advertisement.localName === buttonName) {
      noble.stopScanning();
      peripheral.connect((error) => {
        if (error) {
          connectionListener(false);
          scanButton();
          console.error(error);
          return;