简体   繁体   中英

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). The BLE device divide the file into packages. 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. 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)?

Thank you guys

You should change the remote device to send notifications instead of using reads. That gives maximum throughput.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM