mcumgr_flutter 0.3.2+1 copy "mcumgr_flutter: ^0.3.2+1" to clipboard
mcumgr_flutter: ^0.3.2+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 data and index pairs
final List<Tuple2<int, Uint8List>> firmwareScheme = ...;
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(firmware.firmwareScheme, configuration: configuration);

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

await updateManager.updateWithImageData(image: fwImage!);

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);
4
likes
0
pub points
81%
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

License

unknown (license)

Dependencies

fixnum, flutter, protobuf, rxdart, tuple

More

Packages that depend on mcumgr_flutter