uni.writeBLECharacteristicValue({
deviceId,
serviceId,
characteristicId,
value: data,
success(res) {
console.log('writeBLECharacteristicValue success'+ JSON.stringify(res));
uni.showToast({
title:"指令发送成功",
duration:2000
})
},
fail: e => {
console.log('writeBLECharacteristicValue,错误码:'+ JSON.stringify(e));
uni.showToast({
title:JSON.stringify(e),
duration:5000
})
that.device.name = JSON.stringify(e)
},
complete() {
uni.hideLoading();
}
})

- 发布:2024-08-13 18:57
- 更新:2024-08-13 19:41
- 阅读:393
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: WINDOWS10
HBuilderX类型: 正式
HBuilderX版本号: 4.24
手机系统: Android
手机系统版本号: Android 13
手机厂商: vivo
手机机型: vivo Y66iA
页面类型: vue
vue版本: vue2
打包方式: 云端
项目创建方式: HBuilderX
示例代码:
操作步骤:
uni.writeBLECharacteristicValue({
deviceId,
serviceId,
characteristicId,
value: data,
success(res) {
console.log('writeBLECharacteristicValue success'+ JSON.stringify(res));
uni.showToast({
title:"指令发送成功",
duration:2000
})
},
fail: e => {
console.log('writeBLECharacteristicValue,错误码:'+ JSON.stringify(e));
uni.showToast({
title:JSON.stringify(e),
duration:5000
})
that.device.name = JSON.stringify(e)
},
complete() {
uni.hideLoading();
}
})
uni.writeBLECharacteristicValue({
deviceId,
serviceId,
characteristicId,
value: data,
success(res) {
console.log('writeBLECharacteristicValue success'+ JSON.stringify(res));
uni.showToast({
title:"指令发送成功",
duration:2000
})
},
fail: e => {
console.log('writeBLECharacteristicValue,错误码:'+ JSON.stringify(e));
uni.showToast({
title:JSON.stringify(e),
duration:5000
})
that.device.name = JSON.stringify(e)
},
complete() {
uni.hideLoading();
}
})
预期结果:
uni.writeBLECharacteristicValue({
deviceId,
serviceId,
characteristicId,
value: data,
success(res) {
console.log('writeBLECharacteristicValue success'+ JSON.stringify(res));
uni.showToast({
title:"指令发送成功",
duration:2000
})
},
fail: e => {
console.log('writeBLECharacteristicValue,错误码:'+ JSON.stringify(e));
uni.showToast({
title:JSON.stringify(e),
duration:5000
})
that.device.name = JSON.stringify(e)
},
complete() {
uni.hideLoading();
}
})
uni.writeBLECharacteristicValue({
deviceId,
serviceId,
characteristicId,
value: data,
success(res) {
console.log('writeBLECharacteristicValue success'+ JSON.stringify(res));
uni.showToast({
title:"指令发送成功",
duration:2000
})
},
fail: e => {
console.log('writeBLECharacteristicValue,错误码:'+ JSON.stringify(e));
uni.showToast({
title:JSON.stringify(e),
duration:5000
})
that.device.name = JSON.stringify(e)
},
complete() {
uni.hideLoading();
}
})
实际结果:
uni.writeBLECharacteristicValue({
deviceId,
serviceId,
characteristicId,
value: data,
success(res) {
console.log('writeBLECharacteristicValue success'+ JSON.stringify(res));
uni.showToast({
title:"指令发送成功",
duration:2000
})
},
fail: e => {
console.log('writeBLECharacteristicValue,错误码:'+ JSON.stringify(e));
uni.showToast({
title:JSON.stringify(e),
duration:5000
})
that.device.name = JSON.stringify(e)
},
complete() {
uni.hideLoading();
}
})
uni.writeBLECharacteristicValue({
deviceId,
serviceId,
characteristicId,
value: data,
success(res) {
console.log('writeBLECharacteristicValue success'+ JSON.stringify(res));
uni.showToast({
title:"指令发送成功",
duration:2000
})
},
fail: e => {
console.log('writeBLECharacteristicValue,错误码:'+ JSON.stringify(e));
uni.showToast({
title:JSON.stringify(e),
duration:5000
})
that.device.name = JSON.stringify(e)
},
complete() {
uni.hideLoading();
}
})
bug描述:
uni-app在app端(android)调用蓝牙写入特征值报错10013;微信小程序写入正常
2 个回复
D哥 (作者)
打印了日志,问题解决了,安卓APP连接蓝牙成功后,需要延迟600-1000ms,这样就能拿到特征值
BFC
你好,打印检查一下deviceId 参数