Skip to content

Bug Report: First notification data is lost when device sends data immediately upon subscription #27

Description

@konkong

Description

When subscribing to a BLE characteristic, if the peripheral device sends data immediately after the CCCD write (subscription enable) is completed, the first chunk of data is not received by the JavaScript callback. Subsequent notifications are received normally.

Environment

  • **Node Version:22.22.3
  • **Java Version:openjdk 17.0.2
  • **React Native Version:0.83.9
  • OS: [Android] Ios has not been tested

Steps To Reproduce

  1. Connect to a BLE peripheral that is configured to send a response immediately upon receiving a CCCD subscription enable command.
  2. Call subscribeToCharacteristic for the target notify characteristic.
  3. Observe the logs. The first data packet sent by the device right after subscription is missing.
  4. Trigger another action on the device to send more data. Subsequent packets are received successfully.

Expected Behavior

All data sent by the peripheral after the subscription promise resolves should be captured by the callback.

Actual Behavior

The very first notification payload is dropped/lost. Only subsequent notifications trigger the callback.

Code Snippet

Here is the current subscription implementation:

private async subscribeToNotifications(): Promise<void> {
  await this.unsubscribeFromNotifications();

  const isSubscribed = bleManager.isSubscribedToCharacteristic(
    this.deviceId,
    this.serviceUUID,
    this.notifyCharUUID,
  );
  
  logger.debug('transport', 'ble.notify.current_status', {
    deviceId: this.deviceId,
    isSubscribed,
  });

  this.notifySubscription = await bleManager.subscribeToCharacteristic(
    this.deviceId,
    this.serviceUUID,
    this.notifyCharUUID,
    (_characteristicId, data) => {
      logger.debug('transport', 'ble.notify.received', {
        deviceId: this.deviceId,
        length: data.length,
      });
      this.receiveCallback?.(new Uint8Array(data));
    },
  );
  
  logger.info('transport', 'ble.notify.subscribed', {
    deviceId: this.deviceId,
  });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions