Skip to content

kshinya/react-native-nordic-dfu

 
 

Repository files navigation

react-native-nordic-dfu npm version CircleCI Known Vulnerabilities

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

Getting started

$ yarn add react-native-nordic-dfu

Mostly automatic installation

$ react-native link react-native-nordic-dfu

API

startDFU

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
    • obj.deviceAddress string The MAC address for the device that should be updated
    • obj.deviceName string The name of the device in the update notification (optional, default null)
    • obj.filePath string The file system path to the zip-file used for updating

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

DFUEmitter

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

Full Example

See: example/index.js

Manual installation

iOS

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-nordic-dfu and add RNNordicDfu.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNNordicDfu.a to your project's Build PhasesLink Binary With Libraries
  4. Drag and drop Zip.framework and iOSDFULibrary.framework into your project
  5. Add $(SRCROOT)/../node_modules/react-native-nordic-dfu/ios as a recursive framework search path under [your project] > Build Settings > Search Paths > Framework Search Paths
  6. Add both frameworks under [your project] > General > Embedded binaries
  7. Ensure that [your project] > Build Settings > Build Options > Always Embed Swift Standard Libraries is set to Yes
  8. Call [RNNordicDfu setCentralManagerGetter:<...>] with a block argument that returns your CBCentralManager 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.
  9. If you want control over the CBCentralManager instance after the DFU process is done you might need to provide the onDFUComplete and onDFUError callbacks to transfer back delegate control (see example project).
  10. Run your project (Cmd+R)<

Android

  1. 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 the getPackages() method
  1. 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')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle: compile project(':react-native-nordic-dfu')

Development and contribution

iOS

This package contains pre-built frameworks for Nordic's native DFU library. To upgrade to the latest version of this library:

  1. Update library version in ios/Cartfile
  2. Navigate to ios/
  3. Execute carthage update --platform iOS
  4. Copy the files Zip.framework and iOSDFULibrary.framework to ios/
  5. Rebuild demo project

Resources

Sponsored by

pilloxa

About

Nordic Device Firmware Update for React Native

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 67.0%
  • Java 14.4%
  • JavaScript 8.9%
  • C 7.6%
  • Python 2.1%