boskokg / flutter_blue_plus

Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android and iOS
Other
695 stars 436 forks source link

[Help]: Issue Enabling Notifications for a Characteristic #675

Closed ellik159 closed 9 months ago

ellik159 commented 9 months ago

Requirements

Have you checked this problem on the example app?

No

FlutterBluePlus Version

1.28.7

Flutter Version

3.13.9

What OS?

Android

OS Version

13

Bluetooth Module

Dont know

What is your problem?

The problem occurs when trying to enable notifications for a characteristic. In the example app, it works fine, but in my own app, where I'm using a provider with Riverpod, it doesn't work and I get the following error:

CCCD descriptor for characteristic not found This is my code.

Future<void> connectToDevice(BluetoothDevice device) async {
    try {
      await device.connect(mtu: null);
      // state = device;
      final services = await device.discoverServices();

      for (var service in services) {
        for (var char in service.characteristics) {
          if (char.uuid.uuid == "0000ffe4-0000-1000-8000-00805f9a34fb") {
            print(char.descriptors);
            char.lastValueStream.listen((event) {
              print(event);
            });
            await char.setNotifyValue(true);
          }
        }
      }
    } catch (e) {
      // Manejar el error
      await device.disconnect(queue: false);
      print('Error al conectar: $e');
      throw Exception();
    }

In prints show like the descriptor exist buy when i try to connect throw this

Logs

I/flutter (24903): [FBP] [[ OnDiscoveredServices ]] result: {error_string: GATT_SUCCESS, success: 1, remote_id: D7:D2:9B:8F:E9:F0, error_code: 0, services: [{included_services: [], characteristics: [{descriptors: [], service_uuid: 1800, remote_id: D7:D2:9B:8F:E9:F0, characteristic_uuid: 2a00, properties: {broadcast: 0, write_without_response: 0, notify_encryption_required: 0, read: 1, authenticated_signed_writes: 0, extended_properties: 0, indicate: 0, indicate_encryption_required: 0, write: 1, notify: 0}}, {descriptors: [], service_uuid: 1800, remote_id: D7:D2:9B:8F:E9:F0, characteristic_uuid: 2a01, properties: {broadcast: 0, write_without_response: 0, notify_encryption_required: 0, read: 1, authenticated_signed_writes: 0, extended_properties: 0, indicate: 0, indicate_encryption_required: 0, write: 0, notify: 0}}, {descriptors: [], service_uuid: 1800, remote_id: D7:D2:9B:8F:E9:F0, characteristic_uuid: 2a04, properties: {broadcast: 0, write_without_response: 0, notify_encryption_required: 0, read: 1, authenti
D/BluetoothGatt(24903): onConnectionUpdated() - Device=D7:D2:9B:8F:E9:F0 interval=24 latency=10 timeout=400 status=0
I/flutter (24903): [BluetoothDescriptor{remoteId: D7:D2:9B:8F:E9:F0, serviceUuid: 0000ffe5-0000-1000-8000-00805f9a34fb, characteristicUuid: 0000ffe4-0000-1000-8000-00805f9a34fb, descriptorUuid: 2902, lastValue: []}]
I/flutter (24903): []
I/flutter (24903): [FBP] <getAdapterState> result: {adapter_state: 4}
I/flutter (24903): [FBP] <setNotifyValue> args: {remote_id: D7:D2:9B:8F:E9:F0, service_uuid: 0000ffe5-0000-1000-8000-00805f9a34fb, secondary_service_uuid: null, characteristic_uuid: 0000ffe4-0000-1000-8000-00805f9a34fb, force_indications: false, enable: true}
D/[FBP-Android](24903): [FBP] onMethodCall: setNotifyValue
D/BluetoothGatt(24903): setCharacteristicNotification() - uuid: 0000ffe4-0000-1000-8000-00805f9a34fb enable: true
W/[FBP-Android](24903): [FBP] CCCD descriptor for characteristic not found: 0000ffe4-0000-1000-8000-00805f9a34fb
I/flutter (24903): [FBP] <setNotifyValue> result: false
ellik159 commented 9 months ago

Update Fixed , update to new version