项目作者: keton

项目描述 :
Typescript compatible Noble base class for manipulating BLE peripheral devices
高级语言: TypeScript
项目地址: git://github.com/keton/noble_base.git
创建时间: 2017-09-14T12:09:02Z
项目社区:https://github.com/keton/noble_base

开源协议:MIT License

下载


noble_base

Typescript compatible Noble base class for manipulating BLE peripheral devices

Install

  1. npm install noble_base

Usage

Take a look at the src/examples. Basic pattern is as follows:

  1. Extend NobleBase.Base class

    1. class ExamplePeripheral extends NobleBase.Base {
    2. public is(peripheral: Noble.Peripheral): boolean {
    3. //return true if you want connect to this peripheral
    4. }
    5. protected async onConnectAndSetupDone() {
    6. //do something when peripheral is connected
    7. }
    8. }
  2. Implement is() and onConnectAndSetupDone() methods
  3. In your application code instantiate ScanHelper for your child class
    1. let scanHelper = new NobleBase.ScanHelper<ExamplePeripheral>(ExamplePeripheral);
  4. (optional) Apply scan filter
    1. scanHelper.setScanFilter((peripheral) => {
    2. //return true if peripheral should be connected
    3. });
  5. (optional) Attach device discovered callback
    1. //called each time new SimplePeripheral is connected
    2. const deviceDiscoveredCallback = (peripheral: ExamplePeripheral) => {
    3. //do something with peripheral
    4. }
    5. scanHelper.on('discoveredDevice', deviceDiscoveredCallback);
  6. Start scanning
    1. scanHelper.discoverAll();
  7. Done!