Skip to content

wcoder/Flutter-nRF-Connect-Device-Manager

 
 

Repository files navigation

nRF Connect Device Manager

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

BETA 🧪: This library is still in beta. We are working on improving it and adding more features. If you have any suggestions or find any bugs, please create an issue or a pull request. Also future versions of this library may introduce breaking changes.


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);

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 read logs from the device, use FirmwareUpdateLogger:

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

About

A Flutter plugin for McuMgr libraries for Android and iOS.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 56.8%
  • Swift 32.8%
  • Kotlin 8.6%
  • Ruby 1.1%
  • Other 0.7%