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.
- Android:
minSdkVersion 19
- iOS:
13.0
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();
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);
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"); });
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();
After the update is finished, call kill
to kill the manager, otherwise it will lead to memory leaks and other issues:
updateManager.kill();
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}"); } });