在蓝牙发送数据过程中,蓝牙设备自动断开,请问是什么原因
发布于 6 年前 作者 juan00 1831 次浏览 来自 问答
  • 当前 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)

//that.openBlueTooth()

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’

})

}

}

}

})

//硬件返回数据

//that.openlockBack()

},

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

2 回复

在安卓上, 我也频繁遇到这个问题. 你找到解决办法了吗?

麻烦在手机微信那里上传下日志: 我->设置->帮助与反馈右上角有个上报日志的入口,麻烦提供一下微信号,时间点

回到顶部