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

πŸ› Long read characteristic

Open ezamp opened this issue 1 year ago β€’ 1 comments

Prerequisites

  • [X] I checked the documentation and FAQ without finding a solution
  • [X] I checked to make sure that this issue has not already been filed

Expected Behavior

The readCharacteristicForService should perform multiple read (with offset) if the value size is bigger than the MTU.

Current Behavior

The read function performs one request, and the read value has MTU as the maximum size.

Library version

3.4.0

Device

Android 12 and iOS 17.4.1

Environment info

System:
  OS: macOS 14.6.1
  CPU: (8) x64 Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz
  Memory: 40.66 MB / 8.00 GB
  Shell:
    version: β€œ5.9”
    path: /bin/zsh
Binaries:
  Node:
    version: 21.7.1
    path: ~/.nvm/versions/node/v21.7.1/bin/node
  Yarn:
    version: 1.22.19
    path: ~/.yarn/bin/yarn
  npm:
    version: 10.8.0
    path: ~/.nvm/versions/node/v21.7.1/bin/npm
  Watchman:
    version: 2024.03.18.00
    path: /usr/local/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.1
      - iOS 18.1
      - macOS 15.1
      - tvOS 18.1
      - visionOS 2.1
      - watchOS 11.1
  Android SDK:
    API Levels:
      - β€œ23"
      - β€œ28”
      - β€œ29"
      - β€œ30”
      - β€œ31"
      - β€œ32”
      - β€œ33"
      - β€œ34”
    Build Tools:
      - 28.0.3
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 32.0.0
      - 33.0.0
      - 33.0.1
      - 33.0.2
      - 34.0.0
    System Images:
      - android-27 | Google Play Intel x86 Atom
      - android-28 | Google Play Intel x86 Atom
      - android-29 | Google APIs Intel x86 Atom
      - android-30 | Intel x86_64 Atom
      - android-30 | Google APIs Intel x86 Atom
      - android-30 | Google APIs Intel x86_64 Atom
      - android-30 | Google Play Intel x86 Atom
      - android-30 | Google Play Intel x86 Atom_64
      - android-31 | Intel x86_64 Atom
      - android-31 | Google APIs Intel x86_64 Atom
      - android-31 | Google Play Intel x86_64 Atom
      - android-32 | Google APIs Intel x86_64 Atom
      - android-32 | Google Play Intel x86 Atom_64
      - android-33 | Google APIs Intel x86_64 Atom
      - android-UpsideDownCakePrivacySandbox | Google Play ARM 64 v8a
      - android-UpsideDownCakePrivacySandbox | Google Play Intel x86_64 Atom
    Android NDK: 22.1.7171670
IDEs:
  Android Studio: 2024.1 AI-241.15989.150.2411.11948838
  Xcode:
    version: 16.1/16B40
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.10
    path: /usr/local/opt/openjdk@17/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  β€œ@react-native-community/cli”: Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.74.5
    wanted: 0.74.5
  react-native-macos: Not Found
npmGlobalPackages:
  β€œ*react-native*β€œ: Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Steps to reproduce

  1. …
  2. …

Formatted code sample or link to a repository

try {
  const isConnected = await device.isConnected()
  if (!isConnected) {
    await manager.connectToDevice(device.id)
    store.dispatch(connectBleDevice({ device }))
    try {
      await manager.requestMTUForDevice(device.id, MTU)
      await manager.requestConnectionPriorityForDevice(device.id, ConnectionPriority.High)
    } catch (e) {
      log(β€˜[connectToDevice] mtu error:β€˜, e)
    }
  } else {
    store.dispatch(connectBleDevice({ device }))
    await manager.requestMTUForDevice(device.id, MTU)
  }
} catch (e) {
  log(β€˜[connectToDevice]’, e)
  await connect()
}

try {
  const connected = await device.isConnected()
  if (connected) {
    await device.discoverAllServicesAndCharacteristics()
    const read = await device.readCharacteristicForService(
      SERVICE_UUID,
      char
    )
    return read.value
  }
} catch (e) {
  log(β€˜[readFromGateway] ’, e)
}

Relevant log output

No relevant log

Additional information

No response

ezamp avatar Jan 10 '25 14:01 ezamp

Hello @ezamp. Thank you for raising this topic. I'll add it to the backlog for future enhancements. If you'd like to contribute, pull requests are always welcome!

aliberski avatar Jan 16 '25 16:01 aliberski