微信小程序蓝牙启用监听notifyBLECharacteristicValueChange,返回ok。然后调用writeBLECharacteristicValue接口发送数据,一直显示10008。已经按照网上的说法延时1秒发送数据,仍然返回10008。如果不启用监听,直接发送数据,是可以成功发送的。以下是相关代码:
wx.notifyBLECharacteristicValueChange({
deviceId: that.data.connectedDeviceId,
serviceId: that.data.serviceId,
characteristicId: that.data.resWifiSettingsCharacterId,
state: true,
success: function(res) {
console.log(res)
},
fail: function(res) {
console.log(res)
},
complete: function(res) {
setTimeout(function() {
wx.writeBLECharacteristicValue({
deviceId: that.data.connectedDeviceId,
serviceId: that.data.serviceId,
characteristicId: that.data.reqWifiSettingsCharacterId,
value: utils.hexToArraybuffer(1),
success: function (res) {
console.log('Send request wifi setting successfully')
},
fail: function (res) {
console.log('Send request wifi setting unsuccessfully')
console.log(res)
}
})
}, 1000)
}
})
调试日志如下:
可以看到打开监听成功了,然后延时1秒写数据,返回了失败。有谁能帮忙看一下的,万分感谢!!!
setTimeout(() => { wx.notifyBLECharacteristicValueChange({ deviceId, serviceId, characteristicId: item.uuid, state: true, success: function(msg) { console.log("启用低功耗蓝牙设备特征值变化时的 notify 功能 成功 value:"+msg); }, fail: function(err) { console.log("启用低功耗蓝牙设备特征值变化时的 notify 功能 失败 value:"+err); } }) }, 1000);
大兄弟 怎么解决的 ?我也遇到同样的问题