dotintent / react-native-ble-plx

React Native BLE library
Apache License 2.0
3.09k stars 516 forks source link

writeWithResponse error #840

Closed rfw closed 2 years ago

rfw commented 3 years ago

Current Behavior

writeWithResponse error, There are 2 characteristicArr, one is written normally, and the other reports an error

Steps to Reproduce

console.log('--characteristicArr', characteristicArr)
    const characteristics = characteristicArr[0];
    const base64Str = base64.encode(value);
    characteristics.writeWithResponse(base64Str)
        .then(() => {
          console.log('成功写入特征值', '现在点击读取特征值看看吧...')
        })
        .catch(err => {
          console.log('写入特征值出错:', JSON.stringify(err))
        })

error log

{
"message":"Characteristic 0000c302-0000-1000-8000-00805f9b34fb write failed for device 7C:9E:BD:D0:77:3E and service 0000a002-0000-1000-8000-00805f9b34fb",
"errorCode":401,
"attErrorCode":13,
"iosErrorCode":null,
"androidErrorCode":null,
"reason":"GATT exception from MAC address 7C:9E:BD:D0:77:3E, status 13 (GATT_INVALID_ATTR_LEN), type BleGattOperation{description='CHARACTERISTIC_WRITE'}. (Look up status 0x0d here https://android.googlesource.com/platform/external/bluetooth/bluedroid/+/android-5.1.0_r1/stack/include/gatt_api.h)",
"name":"BleError"
}

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions. Both JS and platform logs can be enabled via setLogLevel function call.

{
  "dependencies": {
    "@react-native-community/masked-view": "^0.1.10",
    "@react-native-picker/picker": "^1.15.0",
    "@react-navigation/native": "^5.9.3",
    "@react-navigation/stack": "^5.14.3",
    "eventemitter2": "^6.4.4",
    "eventemitter3": "^4.0.7",
    "final-form": "^4.20.2",
    "moment": "^2.29.1",
    "native-base": "^2.15.2",
    "prop-types": "^15.7.2",
    "react": "^17.0.2",
    "react-final-form": "^6.5.3",
    "react-native": "0.63.4",
    "react-native-ble-plx": "^2.0.2",
    "react-native-circular-progress": "^1.3.7",
    "react-native-config": "^1.4.2",
    "react-native-datepicker": "^1.7.2",
    "react-native-gesture-handler": "^1.10.3",
    "react-native-image-picker": "^3.3.2",
    "react-native-linear-gradient": "^2.5.6",
    "react-native-picker-select": "^8.0.4",
    "react-native-reanimated": "^2.0.0",
    "react-native-safe-area-context": "^3.2.0",
    "react-native-screens": "^2.18.1",
    "react-native-splash-screen": "^3.2.0",
    "react-native-svg": "^12.1.1-0",
    "victory-native": "^35.3.2"
  },
  "devDependencies": {
    "@babel/core": "^7.8.4",
    "@babel/runtime": "^7.8.4",
    "@react-native-community/eslint-config": "^1.1.0",
    "babel-jest": "^25.1.0",
    "cross-env": "^7.0.3",
    "eslint": "^6.5.1",
    "jest": "^25.1.0",
    "metro-react-native-babel-preset": "^0.59.0",
    "miragejs": "^0.1.41",
    "mockjs": "^1.1.0",
    "react-test-renderer": "16.13.1"
  },
  "jest": {
    "preset": "react-native"
  }
}
mciechanowicz commented 2 years ago

Hi.

Does the characteristic you are trying to write have the isWritableWithResponse field as true?