help,wx.onBLECharacteristicValueChange 在android上无法接受返回值,notify开启是成功的,有趣的是在iOS下面一切正常,问了好多人,又说开启notify之后立即就调用了write会发生问题,尝试了延迟和重发依旧没有任何返回值,下图是测试返回的结果
............................................................................................................................
上图是在ios设备的截图,能接收到返回值
..................................................................................................
这实在android设备的,没有返回值
...................................................................................................
- 求问技术支持,这问题该如何解决,是否有解决方案,下面贴出我的代码,帮忙看看是不是我写的有问题
Page({
/** 页面的初始数据 */
data: {
deviceId: 'FD:76:74:35:99:92',
serviceId: '',
services: [],
writeCharacteristicsId: "", // 可写特征值uuid
readCharacteristicsId: "", // 可读特征值uuid
notifyCharacteristicsId: "", // 通知特征值uuid
},
/** 生命周期函数--监听页面加载 */
onLoad: function (opt) {
//初始化蓝牙适配器
wx.openBluetoothAdapter({
success: function (res) {
console.log("初始化蓝牙适配器成功", res);
},
fail: function (err) {
console.log("初始化失败", err)
}
})
//监听蓝牙适配器状态变化事件
wx.onBluetoothAdapterStateChange(res => {
console.log("状态变化", res)
})
},
start: function() {
let that = this;
console.log('监听设备的连接状态');
/** 连接设备 */
wx.createBLEConnection({
deviceId: that.data.deviceId,
success: function (res) {
console.log('连接设备', res);
/** 监听设备的连接状态 */
wx.onBLEConnectionStateChanged(function (res) {
console.log(`device ${res.deviceId} state has changed, connected: ${res.connected}`)
});
/** 连接成功,后开始获取设备的服务列表 */
wx.getBLEDeviceServices({
deviceId: that.data.deviceId,
success: function (res) {
console.log('device services:', res);
that.setData({ services: res.services, serviceId: res.services[0].uuid }, () => {
wx.getBLEDeviceCharacteristics({
deviceId: that.data.deviceId,
serviceId: that.data.serviceId,
success: function (res) {
console.log('device getBLEDeviceCharacteristics:', res.characteristics);
for (var i = 0; i < res.characteristics.length; i++) {
if (res.characteristics[i].properties.notify) {
that.setData({
notifyCharacteristicsId: res.characteristics[i].uuid
})
}
if (res.characteristics[i].properties.write) {
that.setData({
writeCharacteristicsId: res.characteristics[i].uuid
})
}
if (res.characteristics[i].properties.read) {
that.setData({
readCharacteristicsId: res.characteristics[i].uuid
})
}
}
/** 顺序开发设备特征notifiy */
wx.notifyBLECharacteristicValueChanged({
deviceId: that.data.deviceId,
serviceId: that.data.serviceId,
characteristicId: that.data.notifyCharacteristicsId,
state: true,
success: function (res) {
console.log('notifyBLECharacteristicValueChanged success', res);
},
fail: function (res) { console.log('notifyBLECharacteristicValueChanged fail :', res) },
complete: function (res) { }
});
/** 回调获取 设备发过来的数据 */
wx.onBLECharacteristicValueChange(function (res) {
console.log('characteristic value comed:', res.value);
//{value: ArrayBuffer, deviceId: "D8:00:D2:4F:24:17", serviceId: "ba11f08c-5f14-0b0d-1080-007cbe238851-0x600000460240", characteristicId: "0000cd04-0000-1000-8000-00805f9b34fb-0x60800069fb80"}
let buffer = res.value
let dataView = new DataView(buffer)