react-native-ble-manager icon indicating copy to clipboard operation
react-native-ble-manager copied to clipboard

Bluetooth BleManagerDidUpdateValueForCharacteristic event emits Service UUIDs and Characteristics UUIDs different between iOS and Android.

Open lucaswitch opened this issue 3 months ago • 3 comments

Describe the bug When trying to monitor some characteristics the emitted value on iOS the current characteristic/uuid are not in the same format that is given to "startNotification" method and the "BleManagerDidUpdateValueForCharacteristic" event.

To Reproduce Lets try to monitor the device with characteristics and services in the following format:


const HEART_DEVICE_SERVICE_UUID = '0000180D-0000-1000-8000-00805F9B34FB';
const HEART_DEVICE_SERVICE_CHARACTERISTIC_UUID =
  '00002a37-0000-1000-8000-00805f9b34fb';

  let listener = BleManagerEmitter.addListener(
      'BleManagerDidUpdateValueForCharacteristic',
      onCharacteristicChange,
    );
// The full format of UUID was given.
    BleManager.startNotification(id, HEART_DEVICE_SERVICE_UUID, HEART_DEVICE_SERVICE_CHARACTERISTIC_UUID)
      .then(function () {
        onSuccess();
      })
      .catch(function (err) {
        console.error(err);
        onError(err);
      });

But afterwards on characteristic change we receive the above UUIDs on the short format:

 function onCharacteristicChange({
      value,
      peripheral,
      characteristic,
      service,
    }) {
      const isAllowed = peripheral === id;
      // On Apple Devices:
      // Service UUID equals to: '2a37'
      // Characteristic UUID equals to: '180D'
     // On Android devices the UUID is on the format: '0000180D-0000-1000-8000-00805F9B34FB'

      if (isAllowed) {
        onNotify(value);
      }
    }

    let listener = BleManagerEmitter.addListener(
      'BleManagerDidUpdateValueForCharacteristic',
      onCharacteristicChange,
    );

Explanation

The real problem relies on the undefined behavior on BleManagerDidUpdateValueForCharacteristic event between platforms. The provided service UUID and characteristic UUID should be provided back into the BleManagerDidUpdateValueForCharacteristic event callback.

I can confirm that:

  • On Android always the full format is given to the BleManagerDidUpdateValueForCharacteristic callback.
  • On iOS/IpadOs only the short format is given to the BleManagerDidUpdateValueForCharacteristic callback.

Expected behavior

The expected behavior is characteristics UUIDs and services UUIDs provided on "startNotification" be exactly in the same format provided by the BleManagerDidUpdateValueForCharacteristic callback.

The exact react-native-ble-manager version: 11.3.2

Additional context

I think that could be fixed manually but for new users of the library that it's not the expected behavior and could lead many debugging hours to fix that issue since every device can have many characteristic and could lead a completely mess between iOS/Android way of dealing with those strings.

Thank you for the awesome work and effort and continuous integration into this library!

lucaswitch avatar Mar 08 '24 22:03 lucaswitch