- 当前 Bug 的表现(可附上截图)
- 预期表现
- 复现路径
- 提供一个最简复现 Demo
//开启通知-硬件返回数据
notifyBLECharacteristicValueChange() {
let that = this
console.debug(‘characteristicId’, that.data.notiUUID)
wx.notifyBLECharacteristicValueChange({
deviceId: that.data.blueToothItem.deviceId,//设备id that.data.deviceId
serviceId: that.data.serviceId,//服务uuid
characteristicId: that.data.notiUUID,//特征uuid–只读
state: true,//true表示开启Notify,false关闭
success: function (res) {
console.debug(‘通知数据的改变—成功’, res)
setTimeout(() => {
that.toStrFun()
}, 2000)
that.data.isProofread = false
that.data.isOpenBlueTooth = false
},
fail: function (res) {
console.debug(‘通知数据的改变–失败’, res)
if (that.data.isProofread){
//校对时间写入失败
if(that.data.proofreadTimes < 4){
that.data.proofreadTimes ++
setTimeout(()=>{
that.toStrFun()
},1000)
}
if(that.data.proofreadTimes === 4){
that.data.proofreadTimes = 1
that.data.isProofread = false
wx.showToast({
title: ‘时间校对写入失败’,
icon:‘none’
})
}
}
//开锁数据写入失败
if (that.data.isOpenBlueTooth){
if (that.data.proofreadTimes < 4) {
that.data.proofreadTimes++
setTimeout(() => {
that.openBlueTooth()
}, 1000)
}
if (that.data.proofreadTimes === 4) {
that.data.proofreadTimes = 1
that.data.isProofread = false
wx.showToast({
title: ‘开锁写入失败’,
icon: ‘none’
})
}
}
}
})
//硬件返回数据
},
toStrFun: function () {
let that = this
let UUID = that.data.UUID
let serviceId = that.data.serviceId
//调用锁的各种指令
that.lockOrder()
console.debug(‘校对时间指令:’, that.data.hexStrTime)
console.log(‘校对时间’,util.hex2array(that.data.hexStrTime))
// 校准时间
wx.writeBLECharacteristicValue({
// 这里的 deviceId 需要在 getBluetoothDevices 或 onBluetoothDeviceFound 接口中获取that.data.deviceId,
deviceId: that.data.blueToothItem.deviceId,
// 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
serviceId: serviceId,
// 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
characteristicId: UUID,
// 这里的value是ArrayBuffer类型hexStrTime,hexSearch
value: util.hex2array(that.data.hexStrTime),
success(res) {
console.debug(‘writeBLECharacteristicValue success kkkkk’, res)
that.data.isProofread = true;
},
fail(error){
console.debug(‘搜索,连接.开锁error-------’, error)
wx.showToast({
title: ‘发送时间校准失败’,
icon:‘none’
})
}
})
},
蓝牙是连接上的,在发送数据的时候,蓝牙就自动断开了,请问是怎么回事。日志在5月14号10:26分上传,手机是红米:Redmi Note 4x,MIUI版本:MIUI 10.2