- 当前 Bug 的表现(可附上截图)
- 预期表现
- 复现路径
- 提供一个最简复现 Demo
notifyBLECharacteristicValueChange: function (){
var that = this;
wx.notifyBLECharacteristicValueChange({
state: true, // 启用 notify 功能
deviceId: that.data.deviceId,
serviceId: that.data.serviceId,
characteristicId: that.data.notifyCharacteristicId,
success: function (res) {
console.log(“notify启动成功”);
setTimeout(function (){
// ble.monitor_ble(that.data.deviceId,that.data.serviceId,that.data.writeCharacteristicId);
ble.refresh_ble(that.data.connected,that.data.deviceId, that.data.serviceId, that.data.writeCharacteristicId);
}//这个是我做的一个发送刷新命令的函数
,2000
);
setTimeout(function () {
wx.hideToast();
}, 2000);
},
fail: function (res) {
wx.showToast({
title: ‘notify启动失败’,
mask: true
});
}
})
},
/***我把那条函数封装成模块了*/
function ble_write_fun(orderStr, deviceId, serviceId, writeId) {
console.log(“orderStr:”, orderStr);
let order = utils.stringToBytes(orderStr);//字符串转byte
let byteLength = order.byteLength;
console.log(“byteLength:”, byteLength);
wx.writeBLECharacteristicValue({
deviceId: deviceId,
serviceId: serviceId,
characteristicId: writeId,
// 这里的value是ArrayBuffer类型(二进制数组)
value: order.slice(0, 20),//从0-20个字节的数据
success: function (res) {
// console.log(“value:”, utils.ab2str(order));
onBLECharacteristicValueChange(deviceId, serviceId, writeId);
},
fail: function (res) {
console.log(“res:”, res);
}
})
}
function onBLECharacteristicValueChange(deviceId, serviceId, writeId) {
wx.onBLECharacteristicValueChange(function (res) {
console.log(“res.value:”, utils.ab2str(res.value));
var resValueStr = utils.ab2str(res.value);//2进制数组转成字符串
console.log(“读到字符串”, resValueStr);
rev_page_parse(resValueStr,deviceId, serviceId, writeId);
});
}
function refreshPara(connected, deviceId, serviceId, writeId) {
if (connected) {
ble_write_fun(get_cmd, deviceId, serviceId, writeId);//写入发送
}
else {
app.showModal1(“蓝牙已断开”);
}
}
问题是这样。我发送一个刷新命令后开始监听读取数据。数据很小到问题不明显,设备发了528个字节。。然后在APP看到是完整收到,换成小程序后收到的是断断续续不确定。然后设备分包成20个字节发送出来,结论也一样,设备延时发送也一样,,问题是啥情况。。设备发送的数据
Android和ios都有问题么..
android用的是系统接口,每包接受的大小是有限制的,20个字节..
这里最好可以试试https://github.com/search?q=ble原生app看看有没有类似问题,降低排查问题的难度。万分感谢