BLE with 20 devices


#1

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;

  1. foreach to go through the devices
  2. connect with each device
  3. subscribe on Notifications
  4. 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)
      );
    });
  }

#2

Hi buddy @SjorsHooijen

Please share with me your code, I’m creating a simple protoype to read and write characteristic.

Thank you in advance