简体   繁体   English

Flutter 蓝色 从 BLE 设备向 App 发送相当大的文件

[英]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.

相关问题 在 flutter App 中显示从 BLE 设备到 Heart Widget 的值 - Show value from BLE device to Heart Widget in flutter App 如何在后台隔离中使用 flutter_blue 扫描和连接 BLE 设备 - How to use flutter_blue in background isolate to scan & connect with BLE device 使用 Flutter 蓝色发送字符串 - Sending Strings using Flutter Blue flutter_blue:Android 上的 set_notification 和 read_characteristic 错误,BLE 设备在第一次连接尝试时断开连接 - flutter_blue: set_notification and read_characteristic errors on Android, BLE device disconnects on first connection attempt 从 BLE 设备 flutter 收到不完整的响应 - Incomplete responses being received from BLE device flutter Flutter 反应性 ble 或 Flutter 蓝色 package 哪个最好 - Flutter reactive ble or Flutter blue which package is best 获取 BLE 广告数据 - Android scanRecord 到 Flutter Blue ScanResult - Get BLE advertisement data - Android scanRecord to Flutter Blue ScanResult 如何使用 Flutter [Flutter blue] 从蓝牙 LE 设备获取流式更新? - How can you get streamed updates from a Blutooth LE device using Flutter [Flutter blue]? flutter_blue 设备连接永远挂起 - flutter_blue device connect hangs forever 外设 BLE - 可以使用 Flutter 在 IOS 上模拟 BLE 设备吗? - Peripheral BLE - Can Simulate BLE device on IOS using Flutter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM