[英]Flutter Blue Sending Quite Large File from BLE device to App
I need to send a file.txt from a device to my app (worst case almost 2mb).我需要将一个 file.txt 从设备发送到我的应用程序(最坏的情况几乎是 2mb)。 The BLE device divide the file into packages.
BLE 设备将文件分成包。 I don't know if my method is correct, but I create a loop of characteristic.write/characteristic.read telling everytime what package the device has to send.
我不知道我的方法是否正确,但我创建了一个characteristic.write/characteristic.read 循环,每次都告诉设备必须发送什么package。 Here's my code:
这是我的代码:
for(int i = 0; i < packNumber.length; i++) {
initialValue = '9,50,100,$i,0,$checksumId,0/';
await characteristic
.write(utf8.encode(initialValue)).then((wValue) async {
await Future.delayed(Duration(milliseconds: 100)).then((value) async {
await characteristic.read().then((rValue) {
//do something with rVlaue
});
});
});
}
It works, but is it the best solution?它有效,但它是最好的解决方案吗? And in case how can I speed up the transfer (for now I have to set a delay before reading, waiting for characteristic.write to finish)?
如果我怎样才能加快传输速度(现在我必须在读取之前设置一个延迟,等待characteristic.write完成)?
Thank you guys感谢你们
You should change the remote device to send notifications instead of using reads.您应该更改远程设备以发送通知而不是使用读取。 That gives maximum throughput.
这提供了最大的吞吐量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.