Skip to content

Latest commit

 

History

History
61 lines (45 loc) · 1.98 KB

File metadata and controls

61 lines (45 loc) · 1.98 KB

@nativescript-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 and iOS DFU libraries, this plugin provides a native bridge for initiating and monitoring firmware updates across iOS and Android — fully accessible from JavaScript/TypeScript.

Installation

npm install @nativescript-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:

<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:

initiator.setAndroidForeground(false);

Sample:

import { DFUInitiator, DfuProgressEventData, DfuStateChangedEventData } from '@nativescript-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