@nativescript-community/nordic-dfu
Version:
A NativeScript plugin for performing Nordic Bluetooth device firmware updates.
62 lines (45 loc) • 2.03 kB
Markdown
# -community/nordic-dfu
A NativeScript plugin that integrates Nordic Semiconductor’s DFU (Device Firmware Update) library, enabling seamless Bluetooth OTA firmware updates for compatible BLE devices.
Built using Nordic’s official [android](https://github.com/NordicSemiconductor/Android-DFU-Library) and [iOS](https://github.com/NordicSemiconductor/IOS-DFU-Library) DFU libraries, this plugin provides a native bridge for initiating and monitoring firmware updates across iOS and Android — fully accessible from JavaScript/TypeScript.
## Installation
```javascript
npm install -community/nordic-dfu
```
## Usage
By default, android will start the process in the foreground so make sure to add the following permissions in the manifest file:
```xml
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE"/>
```
If you want to avoid this behaviour because you don't really need foreground activity and Google play complains about permissions, it can be disabled on the DFU initiator instance:
```ts
initiator.setAndroidForeground(false);
```
Sample:
```ts
import { DFUInitiator, DfuProgressEventData, DfuStateChangedEventData } from '-community/nordic-dfu';
const myDeviceUUID = 'a string representation of UUID/address';
const filePath = '/test/file.zip';
const initiator = new DFUInitiator(myDeviceUUID);
initiator.on("DFUStateChanged", (args: DfuStateChangedEventData) => {
if (args.state === DfuState.DFU_COMPLETED) {
console.log("DFU completed!");
}
});
initiator.on("DFUProgress", (args: DfuProgressEventData) => {
console.log(`Progress: ${args.percent}%`);
});
const controller = initiator.start(filePath);
// Use controller to manipulate the procedure
setTimeout(() => {
controller.pause();
}, 2000);
setTimeout(() => {
controller.resume();
}, 4000);
setTimeout(() => {
controller.abort();
}, 5000);
```
## License
Apache License Version 2.0