I’m developing an app to get BLE sensor data from about 20 devices but I only get it working for 2 devices or sometimes maybe 4. I’m using the following code to get the data from the devices;
- foreach to go through the devices
- connect with each device
- subscribe on Notifications
- parse the incoming data with extractLogData()
Do I need to unsubscribe from the connect() and startNotification() for each device?
How can I improve my code to get data from 20 devices?
getData() {
console.log('getData');
this.devices.forEach((device: Device) => {
this.ble.connect(device.id).subscribe(
peripheral => {
this.onConnected(device, peripheral);
this.ble.startNotification(peripheral.id, LOG_SCAN_SERVICE_ID, LOG_SCAN_CHARACTERISTIC_ID).subscribe(
data => this.extractLogData(data, device),
() => console.log('Unexpected Error: Failed to subscribe for Log Data notifications'),
);
},
peripheral => this.onDisconnected(device, peripheral)
);
});
}