NordicSemiconductor/Flutter-nRF-Connect-Device-Manager

Help request: Upload firmware ends at FirmwareUpgradeState.confirm

nissaba opened this issue · 1 comments

Hi I need some help.

I am able to send the firmware data but when reaching 100% I get the event confirm and then nothing happens. I do not see under the updateManager any method to confirm or how to confirm any thing so I can reset the device and I never get the FirmwareUpgradeState.success event.

logs I get in the terminal,

flutter: A Upgrade started with 1 images using 'Confirm Only' mode
flutter: W Device capabilities not supported.
flutter: I Cancelling 'Erase App Settings' since device capabilities are not supported.
flutter: I Validation response: {"splitStatus" : 0, "images" : {{"version" : "0.0.10.6", "pending" : false, "active" : true, "bootable" : true, "hash" : 0x6A953AFF74B69E7DBFA84BCF4F44C04B907A5C417450152331D64F4A946E8B68, "permanent" : false, "slot" : 0, "confirmed" : true}, {"slot" : 1, "permanent" : false, "version" : "0.0.10.6", "confirmed" : false, "hash" : 0x6A953AFF74B69E7DBFA84BCF4F44C04B907A5C417450152331D64F4A946E8B68, "pending" : false, "active" : false, "bootable" : true}}}
flutter: E Request (Group: image, seq: 1) failed: Insufficient MTU: 249.)
flutter: I MTU set to 249
.....
.....
flutter: Confirm

and the code I used from reading the "documentation" on the pub.dev page.

 final managerFactory = FirmwareUpdateManagerFactory();
// `deviceId` is a String with the device's MAC address (on Android) or UUID (on iOS)
    final updateManager = await managerFactory.getUpdateManager(_deviceID!);
// call `setup` before using the manager
    final updateStream = updateManager.setup();

    Uint8List content = loadFirmware();
   

    // `firmware` is a List of data and index pairs
    final List<Tuple2<int, Uint8List>> firmwareScheme = [Tuple2(1, content)];
    const configuration = FirmwareUpgradeConfiguration(
      estimatedSwapTime: Duration(seconds: 0),
      byteAlignment: ImageUploadAlignment.fourByte,
      eraseAppSettings: true,
      pipelineDepth: 1,
    );
// `configuration` is an optional parameter. If not provided, default values will be used.

    final logger = updateManager.logger;
    _loggerSub = logger.logMessageStream.listen((event) {
      for (var msg in event) {
        print("${msg.level.shortName} ${msg.message}");
      }
    });

    updateManager.update(firmwareScheme, configuration: configuration).catchError((e) {
      AlertDialog alert = const AlertDialog(
        title: Text('Firmware Upload Error'),
        content: Text('An error happened while uploading the firmware, please reset Egrid manually'),
      );
      showDialog(
          context: locator.get<NavigationService>().navigatorKey.currentContext!,
          builder: (ctx) {
            return alert;
          });
      return e;
    });

    _updateStateStreamSub = updateManager.updateStateStream?.listen((event) async {
      print(event);
      if (event == FirmwareUpgradeState.success) {
      //never gets called 
        await _updateStateStreamSub?.cancel();
        await _progressStreamSub?.cancel();
        await connection?.cancel();
      } else if (event == FirmwareUpgradeState.confirm) {
         // ????what do here 
      } else {}
    });

    _progressStreamSub = updateManager.progressStream.listen((event) {
      locator.get<BikeViewModel>().firmwareProgres = event.bytesSent / event.imageSize * 100;
      locator.get<BikeViewModel>().firmwareProgressUpdate =
          "${event.bytesSent.fileSize(round: 1)} / ${event.imageSize.fileSize(round: 1)} bytes sent";
    });

fixed my problem. the updateManager was not set to a object property field.