writeCharacteristicValue Response for HarmonyOS 鸿蒙Next. Error Code: -10, message: {"code":-10,"message":"Inner error."}
writeCharacteristicValue Response for HarmonyOS 鸿蒙Next. Error Code: -10, message: {“code”:-10,“message”:“Inner error.”}
writeCharacteristicValue Response. Error Code: -10, message: {"code":-10,"message":"Inner error."}此错误是什么原因?
hilog日志如下:
行 1133: 11-07 17:13:52.847 28346 28346 I C00101/apppool/Bluetooth: [napi_bluetooth_gatt_client.cpp(WriteCharacteristicValueEx:563)]enter
行 1134: 11-07 17:13:52.847 28346 28346 I C00101/apppool/Bluetooth: [napi_bluetooth_utils.cpp(ParseArrayBuffer:132)]arraybuffer size is 16
行 1136: 11-07 17:13:52.848 28346 28346 I C00101/apppool/Bluetooth: [napi_bluetooth_utils.cpp(ParseArrayBuffer:132)]arraybuffer size is 2
行 1137: 11-07 17:13:52.848 28346 28346 I C00101/apppool/Bluetooth: [napi_bluetooth_utils.cpp(ParseArrayBuffer:132)]arraybuffer size is 2
行 1138: 11-07 17:13:52.849 28346 28346 I C00101/apppool/Bluetooth: [napi_parser_utils.cpp(NapiParseGattWriteType:365)]gattWriteType: WRITE
行 1170: 11-07 17:13:52.871 38991 27886 I C05A02/bluetooth_service/PrivacyManagerProxy: [AddPermissionUsedRecord:57]Result from server data = 0
行 1171: 11-07 17:13:52.872 28346 28346 I C00101/apppool/Bluetooth: [napi_timer.cpp(Register:57)]timerId: 11
行 1242: 11-07 17:13:52.975 38991 31139 I C00104/bluetooth_service/bt_btif: [11]HAL bt_gatt_callbacks->client->write_characteristic_cb
行 1243: 11-07 17:13:52.976 38991 31197 I C00102/bluetooth_service/Bluetooth: [12][bluetooth_gatt_client_server.cpp(OnCharacteristicWrite:142)]ret: -10
行 1244: 11-07 17:13:52.976 38991 31197 I C00102/bluetooth_service/Bluetooth: [12][bluetooth_gatt_client_callback_proxy.cpp(OnCharacteristicWrite:105)]BluetoothGattClientCallbackProxy::OnCharacteristicWrite Triggered!
行 1245: 11-07 17:13:52.977 28346 30278 I C00101/apppool/Bluetooth: [bluetooth_gatt_client_callback_stub.cpp(OnCharacteristicWriteInner:128)]BluetoothGattClientCallbackStub::OnCharacteristicWriteInner Triggered!
行 1246: 11-07 17:13:52.977 28346 30278 I C00101/apppool/Bluetooth: [bluetooth_gatt_client.cpp(OnCharacteristicWrite:209)]ret:-10, length:0
行 1247: 11-07 17:13:52.977 28346 30278 I C00101/apppool/Bluetooth: [napi_bluetooth_gatt_client_callback.cpp(OnCharacteristicWriteResult:75)]UUID: 0000FE02-0000-1000-8000-00805F9B34FB, ret: -10
行 1248: 11-07 17:13:52.977 28346 30278 I C00101/apppool/Bluetooth: [napi_async_work.cpp(CallFunction:147)]enter
行 1249: 11-07 17:13:52.977 28346 30278 I C00101/apppool/Bluetooth: [napi_timer.cpp(Unregister:68)]timerId: 11
行 1250: 11-07 17:13:52.977 28346 28346 E C00101/apppool/Bluetooth: [napi_bluetooth_utils.cpp(GetCallbackErrorValue:37)]errCode: -10
行 1251: 11-07 17:13:52.977 28346 28346 I C00101/apppool/Bluetooth: [napi_bluetooth_ble_utils.cpp(ConvertBLECharacteristicToJS:128)]uuid: 0000FE02-0000-1000-8000-00805F9B34FB
行 1252: 11-07 17:13:52.977 28346 28346 I C00101/apppool/Bluetooth: [napi_bluetooth_ble_utils.cpp(ConvertBLEDescriptorVectorToJS:163)]size: 1
行 1253: 11-07 17:13:52.977 28346 28346 I C00101/apppool/Bluetooth: [napi_bluetooth_ble_utils.cpp(ConvertBLEDescriptorToJS:181)]uuid: 00002902-0000-1000-8000-00805F9B34FB
行 1544: 11-07 17:13:55.138 28346 28346 I C00101/apppool/Bluetooth: [napi_bluetooth_gatt_client.cpp(WriteCharacteristicValueEx:563)]enter
行 1545: 11-07 17:13:55.138 28346 28346 I C00101/apppool/Bluetooth: [napi_bluetooth_utils.cpp(ParseArrayBuffer:132)]arraybuffer size is 16
行 1546: 11-07 17:13:55.138 28346 28346 I C00101/apppool/Bluetooth: [napi_bluetooth_utils.cpp(ParseArrayBuffer:132)]arraybuffer size is 2
行 1547: 11-07 17:13:55.138 28346 28346 I C00101/apppool/Bluetooth: [napi_bluetooth_utils.cpp(ParseArrayBuffer:132)]arraybuffer size is 2
行 1549: 11-07 17:13:55.139 28346 28346 I C00101/apppool/Bluetooth: [napi_parser_utils.cpp(NapiParseGattWriteType:365)]gattWriteType: WRITE
行 1553: 11-07 17:13:55.140 38991 31266 I C057C1/bluetooth_service/IPCWorkThread: ThreadHandler 124: proto:0 policy:0 name:OS_IPC_156_31266 invoker:1946656256
行 1556: 11-07 17:13:55.141 38991 39011 I C05A02/bluetooth_service/PrivacyManagerProxy: [AddPermissionUsedRecord:57]Result from server data = 0
行 1557: 11-07 17:13:55.141 28346 28346 I C00101/apppool/Bluetooth: [napi_timer.cpp(Register:57)]timerId: 12
行 1613: 11-07 17:13:55.225 38991 31137 I C00104/bluetooth_service/bt_btif: [11]HAL bt_gatt_callbacks->client->write_characteristic_cb
行 1614: 11-07 17:13:55.226 38991 31198 I C00102/bluetooth_service/Bluetooth: [12][bluetooth_gatt_client_server.cpp(OnCharacteristicWrite:142)]ret: -10
行 1615: 11-07 17:13:55.227 38991 31198 I C00102/bluetooth_service/Bluetooth: [12][bluetooth_gatt_client_callback_proxy.cpp(OnCharacteristicWrite:105)]BluetoothGattClientCallbackProxy::OnCharacteristicWrite Triggered!
行 1616: 11-07 17:13:55.228 28346 30278 I C00101/apppool/Bluetooth: [bluetooth_gatt_client_callback_stub.cpp(OnCharacteristicWriteInner:128)]BluetoothGattClientCallbackStub::OnCharacteristicWriteInner Triggered!
行 1617: 11-07 17:13:55.228 28346 30278 I C00101/apppool/Bluetooth: [bluetooth_gatt_client.cpp(OnCharacteristicWrite:209)]ret:-10, length:0
行 1618: 11-07 17:13:55.228 28346 30278 I C00101/apppool/Bluetooth: [napi_bluetooth_gatt_client_callback.cpp(OnCharacteristicWriteResult:75)]UUID: 0000FE02-0000-1000-8000-00805F9B34FB, ret: -10
行 1619: 11-07 17:13:55.228 28346 30278 I C00101/apppool/Bluetooth: [napi_async_work.cpp(CallFunction:147)]enter
行 1620: 11-07 17:13:55.228 28346 30278 I C00101/apppool/Bluetooth: [napi_timer.cpp(Unregister:68)]timerId: 12
行 1621: 11-07 17:13:55.228 28346 28346 E C00101/apppool/Bluetooth: [napi_bluetooth_utils.cpp(GetCallbackErrorValue:37)]errCode: -10
行 1622: 11-07 17:13:55.228 28346 28346 I C00101/apppool/Bluetooth: [napi_bluetooth_ble_utils.cpp(ConvertBLECharacteristicToJS:128)]uuid: 0000FE02-0000-1000-8000-00805F9B34FB
行 1623: 11-07 17:13:55.228 28346 28346 I C00101/apppool/Bluetooth: [napi_bluetooth_ble_utils.cpp(ConvertBLEDescriptorVectorToJS:163)]size: 1
行 1624: 11-07 17:13:55.228 28346 28346 I C00101/apppool/Bluetooth: [napi_bluetooth_ble_utils.cpp(ConvertBLEDescriptorToJS:181)]uuid: 00002902-0000-1000-8000-00805F9B34FB
更多关于writeCharacteristicValue Response for HarmonyOS 鸿蒙Next. Error Code: -10, message: {"code":-10,"message":"Inner error."}的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
问题已解决,根因是因为api接口第二个参数的问题,第二个参数要填ble.GattWriteType.WRITE_NO_RESPONSE
,不能填写ble.GattWriteType.WRITE
,
this.gattClient.writeCharacteristicValue(this.writeCharacteristic, ble.GattWriteType.WRITE_NO_RESPONSE,
(err: BusinessError) => {
if (err) {
Logger.error(TAG,
`writeCharacteristicValue Response. Error Code: ${err.code}, message: ${JSON.stringify(err)}`);
} else {
Logger.debug(TAG, `writeCharacteristicValue Response.`);
}
})
更多关于writeCharacteristicValue Response for HarmonyOS 鸿蒙Next. Error Code: -10, message: {"code":-10,"message":"Inner error."}的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
-10错误码表示只读,不可写。
大佬,需要怎么设置可写呢,目前代码都是参考api示例设置的,官网也没有demo可以参考,
错误代码 -10 通常表示内部错误。蓝牙通信中,这个错误可能由多种原因引起。以下是一些可能的原因和解决方法:
-
设备连接问题:
- 确保设备已正确连接并且处于可通信状态。
- 检查设备的蓝牙设置,确保其已启用并可见。
-
权限问题:
- 确保应用具有必要的权限来访问蓝牙功能。在 Android 上,这通常包括
BLUETOOTH
、BLUETOOTH_ADMIN
和ACCESS_FINE_LOCATION
权限。 - 在 iOS 上,需要确保应用有适当的权限来使用蓝牙。
- 确保应用具有必要的权限来访问蓝牙功能。在 Android 上,这通常包括
-
蓝牙适配器问题:
- 确保设备的蓝牙适配器正常工作。可以尝试重启蓝牙适配器或设备。
-
固件或驱动问题:
- 确保设备的蓝牙固件是最新的。
- 如果是开发板或其他硬件设备,确保驱动程序是最新的。
-
API 调用问题:
- 检查 API 调用是否正确,参数是否合法。
- 确保在正确的线程上进行蓝牙操作(例如,在 Android 上,蓝牙操作通常需要在主线程或特定的工作线程上执行)。
-
资源限制:
- 检查系统资源是否充足,如内存、CPU 等。
- 确保没有其他应用程序占用了过多的资源。
-
日志和调试信息:
- 查看详细的日志信息,以获取更多关于错误的线索。
- 使用调试工具或日志记录来跟踪问题的根源。
针对帖子标题中提到的“writeCharacteristicValue Response for HarmonyOS 鸿蒙Next. Error Code: -10, message: {“code”:-10,“message”:“Inner error.”}”问题,这里给出直接的专业回答:
在鸿蒙系统中,当你尝试写入蓝牙特征值(characteristic value)时遇到错误代码-10,这通常表示内部错误。这种错误可能由多种原因引起,包括但不限于:
- 蓝牙服务或特征值未正确配置:确保你正在尝试写入的特征值存在且已正确配置在蓝牙设备中。
- 设备连接状态不稳定:检查蓝牙设备的连接状态,确保设备已稳定连接。
- 权限问题:确认你的应用具有写入蓝牙特征值的必要权限。
- 系统或固件问题:有时鸿蒙系统的蓝牙堆栈或固件可能存在bug,导致此类内部错误。
为了解决这个问题,你可以尝试重新连接设备、重启应用或设备,以及检查应用的蓝牙权限设置。如果问题依旧存在,可能需要进一步调查设备的蓝牙日志或联系设备制造商获取支持。
如果问题依旧没法解决请联系官网客服,官网地址是 https://www.itying.com/category-93-b0.html