wx.writeBLECharacteristicValue({ //常用参数不展示,这里只展示异常进入回调
fail(e){ //这里可能会输出10004 或者 10005
console.error("error",e);
}
})
重新扫描一次当前设备的 serviceId 和 characteristicId 即可
let deviceId = this.deviceId;let serviceId = this.serviceId;let characteristicId = this.characteristicId;//vue用户,请自行吧fns的方法放入methodslet fns = {
reconnection(succ,fail){
wx.openBluetoothAdapter({
success :(res) => {
wx.createBLEConnection({
deviceId : deviceId ,
success : (res) => {
fns.searchServices(() => {
fns.serachCharacteristics(succ,fail)
},fail)
},
fail : fail
})
},
fail : fail
})
},
searchServices(succ,fail){
wx.getBLEDeviceServices({
deviceId : deviceId,
success : succ,
fail : fail
})
},
serachCharacteristics(succ,fail){
wx.getBLEDeviceCharacteristics({
deviceId : deviceId,
serviceId : serviceId,
success : succ,
fail : fail
})
},
}//重连fns.reconnection((succ) => { console.log("重连成功,可以调用 wx.writeBLECharacteristicValue")
},(err) => { console.log("err:",err)
});
附送错误码查询地址: 微信小程序官方文档
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69983776/viewspace-2719446/ ,如需转载,请注明出处,否则将追究法律责任。