https://www.jianshu.com/p/de7bd0093c43
关于 微信小程序蓝牙 分包发送 及 多包发送 不返回问题
关于分包发送 20字节分包,微信小程序支持多于20字节发送。但是低功耗蓝牙传输可能会有问题,建议分包发送
for (var i = 0;ie.length;i+=20) {var endLength = 0if (i+20e.length) {var senddata = elet buffer = new ArrayBuffer(20)let dataView = new DataView(buffer)let dataSend = [] for (var j = i; j i + 20; j++) {dataView.setUint8(j - i, senddata[j])dataSend.push(dataView.getUint8(j-i)) }console.log('多包发送的包数据:'+dataSend)wx.writeBLECharacteristicValue({deviceId: app.globalData.deviceId+"",serviceId: app.globalData.writeServicweId+'',characteristicId: app.globalData.writeCharacteristicsId+'',value: buffer,success: function (res) {console.log('多包writeBLECharacteristicValue success',res.errMsg)},fail: function (res) {console.log('发送失败')}})sleep(0.02)}else{ //console.log(app.globalData.writeServicweId+'-----------')var senddata = eif (20 e.length) {endLength = senddata.length-i}else{endLength = senddata.length}let buffer = new ArrayBuffer(endLength)let dataView = new DataView(buffer)let dataSend = []for (var j = i; j senddata.length; j++) {dataView.setUint8(j-i, senddata[j])dataSend.push(dataView.getUint8(j-i))}console.log('最后一包或第一数据:' + dataSend)wx.writeBLECharacteristicValue({deviceId: app.globalData.deviceId+"",serviceId: app.globalData.writeServicweId+'',characteristicId: app.globalData.writeCharacteristicsId+'',value: buffer,success: function (res) {console.log('一包writeBLECharacteristicValue success',res.errMsg) },fail: function (res) {console.log('发送失败')}})sleep(0.02)}}作者:gazyy1链接:https://www.jianshu.com/p/de7bd0093c43來源:简书简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。













