BLE startScan to detect RSSI changes



I’m using BLE.startScan to find some devices.

The problem is: I want to connect only when the RSSI value reaches -40 or more (-39, -38, etc).

The startScan finds my device with a -50 RSSI value, for example, but when I get closer my app ignores this fact, The startScan only return if it finds another device.

I tried use startScan in a loop but looks like startScan is an Observable, which is great and efficient, but I can’t figure it out how to solve my problem.

The code is:
BLE.startScan([]).subscribe(rssi => { console.log(JSON.stringify(rssi)); if(device.rssi > -40) { BLE.stopScan().then(() => { console.log("scan stopped"); }); this.conectarEquipamento(device); } }, error => { console.log(error); alert(JSON.stringify(error)); });


Someone can help me?


this.ble.startScanWithOptions([],{ reportDuplicates:true}).subscribe((device)=>{
console.log(‘Found a BLE device’, device);