Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] PlatformException on subscribeToCharacteristic | Device connects successfully. #882

Open
1 task done
devtyagi-c opened this issue Sep 5, 2024 · 0 comments
Open
1 task done

Comments

@devtyagi-c
Copy link

Describe the bug

(Works fine on Android)

I perform these operations on iOS:

  • Connect to Device, move to a new screen
  • Click on start monitoring button
  • On the click of the button the following operations are performed
    1. Enable notifications on characteristic 86f66001-f706-58a0-95b2-1fb9261e4dc7
    2. Enable notifications on characteristic 86f65002-f706-58a0-95b2-1fb9261e4dc7
    3. Write 0x0213C87462 on characteristic 86f65001-f706-58a0-95b2-1fb9261e4dc7
    4. Write 0x66 on characteristic 86f65001-f706-58a0-95b2-1fb9261e4dc7

And I get this error:

PlatformException (PlatformException(reactive_ble_mobile.Central.(unknown context at $10590a818).Failure:1, The operation couldn’t be completed. (reactive_ble_mobile.Central.(unknown context at $10590a818).Failure error 1.), {}, null))

image

image

Is there any fix for this?

To Reproduce
Steps to reproduce the behavior:
Mentioned above ^

Expected behavior
I should not get this exception, it works perfectly fine on Android.

  • I tried doing the same with a general BLE scanner application (e.g. nRF Connect) and it exhibits the expected behavior as described above

Smartphone / tablet

  • Device: [e.g. iPhone 13]
  • OS: iOS 17.5.1
  • Package version: ^5.3.1

Peripheral device

  • Vendor, model: CUSTOM
  • Does it run a custom firmware / software: yes

Additional context

Here is my code:

Here is my code for the start monitoring button:

Future<void> startMonitoring() async {
    if (state.selectedDeviceId == null) {
      emit(state.copyWith(error: "No device selected"));
      return;
    }

    if (state.connectionState != DeviceConnectionState.connected) {
      emit(state.copyWith(error: "Device not connected"));
      return;
    }

    // Emit initial state
    emit(state.copyWith(isSettingUpMonitoring: true, error: null));

    try {
      await Future.delayed(const Duration(seconds: 2));

      // Enable notifications on 6001
      _monitorSubscription6001 = _monitorCharacteristic
          .execute(
        state.selectedDeviceId!,
        "86f66000-f706-58a0-95b2-1fb9261e4dc7",
        "86f66001-f706-58a0-95b2-1fb9261e4dc7",
      )
          .listen(
        (data) {
          // Emit state when a new value is received from 6001
          log("Received data from 6001: $data");
          emit(state.copyWith(characteristicValue: data.toString(), isMonitoring: true, isSettingUpMonitoring: false));
        },
        onError: (error) {
          emit(state.copyWith(error: error.toString(), isMonitoring: false, isSettingUpMonitoring: false));
        },
      );

      await Future.delayed(const Duration(milliseconds: 200));

      // Enable notifications on 5002
      _monitorSubscription5002 = _monitorCharacteristic
          .execute(
        state.selectedDeviceId!,
        "86f65000-f706-58a0-95b2-1fb9261e4dc7",
        "86f65002-f706-58a0-95b2-1fb9261e4dc7",
      )
          .listen(
        (data) {
          // We do not need to emit the state here when a new value is received from 5002
          log("Received data from 5002: $data");
        },
        onError: (error) {
          emit(state.copyWith(error: error.toString(), isMonitoring: false, isSettingUpMonitoring: false));
        },
      );

      await Future.delayed(const Duration(milliseconds: 200));

      await _writeCharacteristic.execute(
        state.selectedDeviceId!,
        "86f65000-f706-58a0-95b2-1fb9261e4dc7",
        "86f65001-f706-58a0-95b2-1fb9261e4dc7",
        [0x02, 0x13, 0xC8, 0x74, 0x62],
      );

      log("Successfully wrote data to 86f65001-f706-58a0-95b2-1fb9261e4dc7");

      await _writeCharacteristic.execute(
        state.selectedDeviceId!,
        "86f65000-f706-58a0-95b2-1fb9261e4dc7",
        "86f65001-f706-58a0-95b2-1fb9261e4dc7",
        [0x66],
      );

      log("Successfully wrote data to 86f65001-f706-58a0-95b2-1fb9261e4dc7");
    } catch (e) {
      // Emit state when an error occurs
      log("Error: $e");
      emit(state.copyWith(
        error: e.toString(),
        isMonitoring: false,
        isSettingUpMonitoring: false,
      ));
    }
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant