mcumgr_flutter 0.4.1 copy "mcumgr_flutter: ^0.4.1" to clipboard
mcumgr_flutter: ^0.4.1 copied to clipboard

nRF Connect Device Manager library is a Flutter plugin based on Android and iOS nRF Connect Device Manager libraries.

nRF Connect Device Manager #

nRF Connect Device Manager library is a Flutter plugin based on Android and iOS nRF Connect Device Manager libraries.


Supported Platforms #

  • Android: minSdkVersion 19
  • iOS: 13.0

Getting Started #

Creating a manager #

Use UpdateManagerFactory to create an instance of FirmwareUpdateManager:

final managerFactory: UpdateManagerFactory = 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();

Updating the device #

To update the device, call update method on the FirmwareUpdateManager instance:

// `firmware` is a List of Image objects
List<Image> firmwareImages = [];
for (final file in manifest.files) {
  final image = Image(
    image: file.image,
    data: firmwareFileData,
  );
  firmwareImages.add(image);
}

final configuration = const FirmwareUpgradeConfiguration(
      estimatedSwapTime: const Duration(seconds: 0),
      byteAlignment: ImageUploadAlignment.fourByte,
      eraseAppSettings: true,
      pipelineDepth: 1,
    );
// `configuration` is an optional parameter. If not provided, default values will be used.
updateManager.update(firmwareImages, configuration: configuration);

Alternatively, you can use updateWithImageData to update the device with a single image data:

await updateManager.updateWithImageData(image: fwImage!);

Tip

update and updateWithImageData methods are asynchronous, however, they do not return a result of the update process. They only start the update process. To listen for updates, subscribe to the updateStream and progressStream. See also Issue #63 for more information.

Listening for updates #

To listen for updates, subscribe to the updateStream and progressStream:

updateManager.updateStateStream?.listen((event) {
    if (event == FirmwareUpgradeState.success) {
        print("Update Success");
    } else {
        print(event);
    }
});

updateManager.progressStream.listen((event) {
    print("${event.bytesSent} / ${event.imageSize}} bytes sent");
});

Controlling the update #

To control the update, use FirmwareUpdateManager methods:

  /// Pause the update process.
  Future<void> pause();

  /// Resume the update process.
  Future<void> resume();

  /// Cancel update.
  Future<void> cancel();

  /// Check if the progress is in process.
  Future<bool> inProgress();

  /// Check if the progress is paused.
  Future<bool> isPaused();

Killing the manager #

After the update is finished, call kill to kill the manager, otherwise it will lead to memory leaks and other issues:

updateManager.kill();

Reading logs #

To listen for logs, subscribe to the logger.logMessageStream:

updateManager.logger.logMessageStream
        .where((log) => log.level.rawValue > 1) // filter out debug messages
        .listen((log) {
      print(log.message);
    });

To read logs from the device, use readLog method:

List<McuLogMessage> logs =
        await updateManager.logger.readLogs(clearLogs: false);
3
likes
130
pub points
78%
popularity

Publisher

unverified uploader

nRF Connect Device Manager library is a Flutter plugin based on Android and iOS nRF Connect Device Manager libraries.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

fixnum, flutter, protobuf, rxdart, tuple

More

Packages that depend on mcumgr_flutter