对接低功耗中心蓝牙设备,notifyBLECharacteristicValueChange成功,writeBLECharacteristicValue也是成功,但是无法接受设备返回数据,onBLECharacteristicValueChange
lanyatest10(event){
var that = this;
console.log("开始接收数据");
function ab2hex(buffer) {
let hexArr = Array.prototype.map.call(
new Uint8Array(buffer),
function(bit) {
return ('00' + bit.toString(16)).slice(-2)
}
)
return hexArr.join('');
}
wx.onBLECharacteristicValueChange(function (res) {
console.log("characteristicId:" + res.characteristicId)
console.log("serviceId:" + res.serviceId)
console.log("deviceId" + res.deviceId)
console.log("Length:" + res.value.byteLength)
console.log("hexvalue:" + ab2hex(res.value))
that.setData({
info: that.data.info + ab2hex(res.value)
})
})
},
wx.readBLECharacteristicValue
你再写一次, 然后看下监听返回的onBLECharacteristicValueChange
有没有返回值; 也要确定下终端是否给你返回数据了; api没问题的, 建议好好检查, 这种监听 放onload里面统一监听就行, 代码要规整; 我们蓝牙小程序从没出现过这种情况