微信小程序蓝牙启用监听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秒写数据,返回了失败。有谁能帮忙看一下的,万分感谢!!!