This library allows you to do a Device Firmware Update (DFU) of your nrf51 or nrf52 chip from Nordic Semiconductor. It works for both iOS and Android.
For more info about the DFU process, see: Resources
$ yarn add react-native-nordic-dfu
$ react-native link react-native-nordic-dfu
NOTE FOR iOS: After linking the library you must perform step 4-10 of the Manual installation for iOS below.
Starts the DFU process
Observe: The peripheral must have been discovered by the native BLE side so that the bluetooth stack knows about it. This library will not do a scan but only the actual connect and then the transfer. See the example project to see how it can be done in React Native.
Parameters
obj
Object
* identifier
— MAC address (Android) / UUID (iOS)
Examples
import { NordicDFU, DFUEmitter } from "react-native-nordic-dfu";
NordicDFU.startDFU({
deviceAddress: "C3:53:C0:39:2F:99",
name: "Pilloxa Pillbox",
filePath: "/data/user/0/com.nordicdfuexample/files/RNFetchBlobTmp4of.zip"
})
.then(res => console.log("Transfer done:", res))
.catch(console.log);
Returns Promise A promise that resolves or rejects with the deviceAddress
in the return value
Event emitter for DFU state and progress events
Examples
import { NordicDFU, DFUEmitter } from "react-native-nordic-dfu";
DFUEmitter.addlistener("DFUProgress",({percent, currentPart, partsTotal, avgSpeed, speed}) => {
console.log("DFU progress: " + percent +"%");
});
DFUEmitter.addListener("DFUStateChanged", ({state}) => {
console.log("DFU State:", state);
})
See: example/index.js
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-nordic-dfu
and addRNNordicDfu.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNNordicDfu.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Drag and drop
Zip.framework
andiOSDFULibrary.framework
into your project - Add
$(SRCROOT)/../node_modules/react-native-nordic-dfu/ios
as arecursive
framework search path under[your project] > Build Settings > Search Paths > Framework Search Paths
- Add
$(SRCROOT)/../node_modules/react-native-nordic-dfu/ios
as a header search path under[your project] > Build Settings > Search Paths > Header Search Paths
- Add both frameworks under
[your project] > General > Embedded binaries
- Ensure that
[your project] > Build Settings > Build Options > Always Embed Swift Standard Libraries
is set toYes
- Call
[RNNordicDfu setCentralManagerGetter:<...>]
with a block argument that returns yourCBCentralManager
instance (see example project for how this may be done). It is assumed that you have initiated this instance outside of this library, for flexibility. - If you want control over the
CBCentralManager
instance after the DFU process is done you might need to provide theonDFUComplete
andonDFUError
callbacks to transfer back delegate control (see example project). - Run your project (
Cmd+R
)<
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.pilloxa.RNNordicDfuPackage;
to the imports at the top of the file - Add
new RNNordicDfuPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
: include ':react-native-nordic-dfu' project(':react-native-nordic-dfu').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-nordic-dfu/android') - Insert the following lines inside the dependencies block in
android/app/build.gradle
: compile project(':react-native-nordic-dfu')
This package contains pre-built frameworks for Nordic's native DFU library. To upgrade to the latest version of this library:
- Update library version in
ios/Cartfile
- Navigate to
ios/
- Execute
carthage update --platform iOS
- Copy the files
Zip.framework
andiOSDFULibrary.framework
toios/
- Rebuild demo project
- DFU Introduction
- Secure DFU Introduction
- How to create init packet
- nRF51 Development Kit (DK) (compatible with Arduino Uno Revision 3)
- nRF52 Development Kit (DK) (compatible with Arduino Uno Revision 3)