don / ionic-ble-examples

Ionic Framework Bluetooth Low Energy Examples
102 stars 70 forks source link

Event for when a device stops being connected or advertising #7

Closed nimeso closed 6 years ago

nimeso commented 6 years ago

I'm using Ionic and I need to update my devices array when a device stops advertising. We have a physical button that turns off after you hold the button down for a period of time.

Basically:

deviceList = [];

scanForDevices(){
      console.log("scan for devices");
      this.ble.startScan([]).subscribe(device => {
        this.zone.run(() => {
            this.deviceList.push(device);
        });
     this.connect(device);
}

Any help would be awesome. Thanks!

don commented 6 years ago

If you want to see when a device stops advertising, you need to keep scanning getting duplicate records. Try ble.startScanWithOptions. The example shows how to get duplicates, your code will responsible for determining when a device stops advertising.