Skip to content

Not triggering subscribe in scan function #17

@raghavendra-synapptra

Description

@raghavendra-synapptra

@tearforfear007
Thanks for this,

Subscribe is not triggering in scan function. can any body help me on this.
Using Angular 7 and ionic 4
Kindly find the below code

import { Component, NgZone } from '@angular/core';
import { BLE } from '@ionic-native/ble/ngx';
import { Observable } from "rxjs"
// import { NavController } from 'ionic-angular';
// import { ToastController } from 'ionic-angular';

@component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {

devices: any[] = [];
statusMessage: string;

constructor(
// public navCtrl: NavController,
// private toastCtrl: ToastController,
private ble: BLE,
private ngZone: NgZone) {
}

ionViewDidEnter() {
console.log('ionViewDidEnter');
this.scan();
}

onDeviceDiscovered(device) {
console.log('Discovered ' + JSON.stringify(device, null, 2));
this.ngZone.run(() => {
  this.devices.push(device);
});

}

scan() {
this.setStatus('Scanning for Bluetooth LE Devices');
this.devices = []; // clear list

this.ble.scan([], 5).subscribe(
  
  // device => this.onDeviceDiscovered(device), 
  (device) => {
    console.log("inside subscribe")
    this.onDeviceDiscovered(device)}, 
  (error) => {this.scanError(error)}
);

// setTimeout(this.setStatus.bind(this), 5000, 'Scan complete');

}

// If location permission is denied, you'll end up here
scanError(error) {
this.setStatus('Error ' + error);
// let toast = this.toastCtrl.create({
// message: 'Error scanning for Bluetooth low energy devices',
// position: 'middle',
// duration: 5000
// });
// toast.present();
}

setStatus(message) {
console.log(message);
this.ngZone.run(() => {
this.statusMessage = message;
});
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions