Skip to content

Jurpp/react-native-nordic-dfu

 
 

Repository files navigation

react-native-nordic-dfu

This fork contains an update of IOS-Pods-DFU-Library version (4.5.1) and added two timeouts to fix firmware uploads on iOS 13. This readme also contains a setup to not use !use_frameworks in the pod-file.

EDIT: This fork of the ThomasStubbe fork increases the second delay and rate limits the DFU.

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

Installation

Remove react-native-nordic-dfu from your package.json and yarn.lock files and run the following command:

yarn add https://github.com/Jurpp/react-native-nordic-dfu

Minimum requirements

This project has been verified to work with the following dependencies, though other versions may work as well.

Dependency Version
React Native 0.59.4
XCode 10.2
Swift 5.0
CocoaPods 1.6.1
Gradle 5.3.1

iOS

The iOS version of this library has native dependencies that need to be installed via CocoaPods, which is currently the only supported method for installing this library. (PR's for alternative installation methods are welcome!)

Previous versions supported manual linking, but this was prone to errors every time a new version of XCode and/or Swift was released, which is why this support was dropped. If you've previously installed this library manually, you'll want to remove the old installation and replace it with CocoaPods.

CocoaPods

Add the following to your Podfile

target "YourApp" do
  ...
  
  # use_frameworks! # NO NEED TO ENABLE THIS!
  
  pod "react-native-nordic-dfu", path: "../node_modules/react-native-nordic-dfu", :modular_headers => true

  ...
end

and in the same folder as the Podfile run

pod install

Since there's native Swift dependencies you need to set which Swift version your project complies with. If you haven't already done this, open up your project with XCode and add a User-Defined setting under Build Settings: SWIFT_VERSION = <your-swift-version>.

Bluetooth integration

This library needs access to an instance of CBCentralManager, which you most likely will have instantiated already if you're using Bluetooth for other purposes than DFU in your project.

in AppDelegate.m add:

#import "RNNordicDfu.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

  //...
 
 
  [RNNordicDfu setCentralManagerGetter:^() {
    return [[CBCentralManager alloc] initWithDelegate:nil queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)];
  }];
  
  // Reset manager delegate since the Nordic DFU lib "steals" control over it
  [RNNordicDfu setOnDFUComplete:^() {
    NSLog(@"onDFUComplete");
  }];
  [RNNordicDfu setOnDFUError:^() {
    NSLog(@"onDFUError");
  }];
  
  
  //...

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 identifier* of 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

* 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

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

Example project

Navigate to example/ and run

npm install

Run the iOS project with

react-native run-ios

and the Android project with

react-native run-android

Development

PR's are always welcome!

Resources

Sponsored by

pilloxa

About

Nordic Device Firmware Update for React Native

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 35.4%
  • Java 34.1%
  • JavaScript 20.8%
  • Ruby 4.9%
  • Starlark 4.8%