Code Monkey home page Code Monkey logo

react-native-nordic-dfu's Introduction

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

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

react-native-nordic-dfu's People

Contributors

dariuszseweryn avatar looveh avatar niclas-jetset avatar vikeri avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.