Angular-web-bluetooth example does not work

122 views Asked by At

I am trying to read values from a BLE Peripheral under the Angular Framework. For this I tried to use the Angular Web Bluetooth module . This works in principle, but there is a code example on the GitHub page:

value() {
    console.log('Getting Battery level...');

    return this.ble

        // 1) call the discover method will trigger the discovery process (by the browser)
        .discover$({
          acceptAllDevices: true,
          optionalServices: [BatteryLevelService.GATT_PRIMARY_SERVICE]
        })
        .pipe(

          // 2) get that service
          mergeMap((gatt: BluetoothRemoteGATTServer) => {
            return this.ble.getPrimaryService$(gatt, BatteryLevelService.GATT_PRIMARY_SERVICE);
          }),

          // 3) get a specific characteristic on that service
          mergeMap((primaryService: BluetoothRemoteGATTService) => {
            return this.ble.getCharacteristic$(primaryService, BatteryLevelService.GATT_CHARACTERISTIC_BATTERY_LEVEL);
          }),

          // 4) ask for the value of that characteristic (will return a DataView)
          mergeMap((characteristic: BluetoothRemoteGATTCharacteristic) => {
            return this.ble.readValue$(characteristic);
          }),

          // 5) on that DataView, get the right value
          map((value: DataView) => value.getUint8(0))
        )
  }

This leads to the following error message: Argument of type 'OperatorFunction<BluetoothRemoteGATTServer, BluetoothRemoteGATTService>' is not assignable to parameter of type 'OperatorFunction<void | BluetoothRemoteGATTServer, BluetoothRemoteGATTService>'. Type 'void | BluetoothRemoteGATTServer' is not assignable to type 'BluetoothRemoteGATTServer'. Type 'void' is not assignable to type 'BluetoothRemoteGATTServer'.

And I don't know how to fix the error since I am relatively new to Typescript.

0

There are 0 answers