Giter Club home page Giter Club 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

This is a fork from the main library!

  • Please keep in mind the our availability to maintain this fork is limited and is based on our project needs.
  • If need the main documentation you can find it here.
  • This fork contains the latest verisons of iOSDFULibrary & Android-BLE-Library.

Installation

Install and link the NPM package per usual with

npm install --save https://github.com/Salt-PepperEngineering/react-native-nordic-dfu

or

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

For React Native below 60.0 version

react-native link react-native-nordic-dfu

Project Setup

Unfortunately, the ios project is written in Objective-C so you will need to use use_frameworks! :linkage => :static. Note: We are considering rewriting the ios module on Swift, but it depends very much on how much free time we have and how much we needed right now.

Podfile:

  • Flipper Disabled
target "YourApp" do

  ...
  pod "react-native-nordic-dfu", path: "../node_modules/react-native-nordic-dfu"
  ...
  use_frameworks! :linkage => :static
  ...
  :flipper_configuration => FlipperConfiguration.disabled,
  ...

end
  • Flipper enabled
static_frameworks = ['iOSDFULibrary']
pre_install do |installer|
  installer.pod_targets.each do |pod|
    if static_frameworks.include?(pod.name)
      puts "Overriding the static_frameworks? method for #{pod.name}"
      def pod.build_type;
        Pod::BuildType.new(:linkage => :static, :packaging => :framework)
      end
    end
  end
end

target "YourApp" do

  ...
  pod "react-native-nordic-dfu", path: "../node_modules/react-native-nordic-dfu"
  ...
  :flipper_configuration => FlipperConfiguration.enabled,
  ...

end

AppDelegate.mm:

...
#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");
             }];
  ...

}

New Example

  1. cd newExample
  2. yarn setup
  3. Go to newExample/App.tsx
  4. Update the filePath variable with the link to the firmware file
  5. Update the BleManagerService.init('', ''); function with the DFU Service & the device name
  6. Press Connect to Device in Area button
  7. When you see some small info about the device on the screen Press the Start Update
  8. If you have any problems connecting to the Device pleas consult the react-native-ble-manager

Issues

  • For configuration issues please also check this (Pilloxa#171)

Resources

react-native-nordic-dfu's People

Contributors

aluxmanu avatar anees17861 avatar chrischares avatar dariuszseweryn avatar domir avatar ezranbayantemur avatar filipengberg avatar kevinresol avatar looveh avatar manualexsp avatar moonbird-yordi avatar niclas-jetset avatar niklavsbariss avatar robwalkerco avatar samulitam avatar sofiaschn avatar vikeri avatar yannvanhalewyn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-native-nordic-dfu's Issues

Using with Expo

Hi there!

Thanks for the effort for this package. Trying to make it work with react-native-ble-plx and Expo.

Question: Have you had any experience with using the lib with Expo? One idea would be to have an Expo @config-plugin that could (I suppose) do all the alterations in AppDelegate etc in the prebuild.

React native 0.72.4 targeting android 13 build issues

Hi! 👋

I've recently upgraded react-native version to 0.72.4 and found that android no longer builds due to a couple of issues, you can check both of them on reproducible repo https://github.com/Oleksii27/DfuExample on master branch. To reproduce:

cd android
./gradlew build

And you'll notice couple of build errors

  1. minSdkVersion incompatibility:
> Task :react-native-nordic-dfu:processDebugAndroidTestManifest FAILED
/dev/AwesomeProject/node_modules/react-native-nordic-dfu/android/build/intermediates/tmp/manifest/androidTest/debug/tempFile1ProcessTestManifest8717370557204022401.xml:5:5-74 Error:
        uses-sdk:minSdkVersion 18 cannot be smaller than version 21 declared in library [com.facebook.react:react-android:0.72.4] /Users/.gradle/caches/transforms-3/6fe00d6361b0f0c55549aec89a7f6742/transformed/jetified-react-android-0.72.4-debug/AndroidManifest.xml as the library might be using APIs not available in 18
        Suggestion: use a compatible library with a minSdk of at most 18,
                or increase this project's minSdk version to at least 21,
                or use tools:overrideLibrary="com.facebook.react" to force usage (may lead to runtime failures)

See https://developer.android.com/r/studio-ui/build/manifest-merger for more information about the manifest merger.

Which is caused by minSdkVersion 18 in build.gradle

I've solved it by applying a patch, where I inherited projects minSdkVersion, which I believe is a good solution. I could submit a pull request for that if it's fine.

diff --git a/node_modules/react-native-nordic-dfu/android/build.gradle b/node_modules/react-native-nordic-dfu/android/build.gradle
index 548c19d..6ddc13d 100644
--- a/node_modules/react-native-nordic-dfu/android/build.gradle
+++ b/node_modules/react-native-nordic-dfu/android/build.gradle
@@ -15,13 +15,14 @@ apply plugin: 'com.android.library'
 def DEFAULT_COMPILE_SDK_VERSION = 31
 def DEFAULT_BUILD_TOOLS_VERSION = '31.0.0'
 def DEFAULT_TARGET_SDK_VERSION = 31
+def DEFAULT_MIN_SDK_VERSION = 18
 
 android {
     compileSdkVersion project.hasProperty('compileSdkVersion') ? project.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
     buildToolsVersion project.hasProperty('buildToolsVersion') ? project.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION
 
     defaultConfig {
-        minSdkVersion 18
+        minSdkVersion project.hasProperty('minSdkVersion') ? project.minSdkVersion : DEFAULT_MIN_SDK_VERSION
         targetSdkVersion project.hasProperty('targetSdkVersion') ? project.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION
         versionCode 1
         versionName "1.0"
  1. The second one is a gradle lint problem which appears after applying the above patch:
> Task :app:lintDebug FAILED
Lint found 1 errors, 5 warnings. First failure:

/dev/AwesomeProject/android/app/src/main/AndroidManifest.xml: Error: When targeting Android 13 or higher, posting a permission requires holding the POST_NOTIFICATIONS permission (usage from no.nordicsemi.android.dfu.DfuBaseService) [NotificationPermission]

   Explanation for issues of type "NotificationPermission":
   When targeting Android 13 and higher, posting permissions requires holding
   the runtime permission android.permission.POST_NOTIFICATIONS.


The full lint text report is located at:
  /dev/AwesomeProject/android/app/build/intermediates/lint_intermediate_text_report/debug/lint-results-debug.txt

FAILURE: Build failed with an exception.

Which is caused by a native no.nordicsemi.android.dfu.DfuBaseService class, I believe it has something to do with DfuBaseService class using some notification posting, but I don't have much experience with java and I haven't really looked at their code. I have found that Android-DFU-Library uses this permission in their AndroidManifest in the example https://github.com/NordicSemiconductor/Android-DFU-Library/blob/b37200033f5d3fe412994e05dd20dd57e14acfe5/app/src/main/AndroidManifest.xml

Which I suppressed by creating a lint config

<?xml version="1.0" encoding="utf-8" ?>
<lint>
    <issue id="NotificationPermission">
        <ignore regexp="no.nordicsemi.android.dfu.DfuBaseService" />
    </issue>
</lint>
lint {
        // https://github.com/bumptech/glide/issues/4940 which I adapted from here
        lintConfig = file("$rootDir/lintConfig.xml")
    }

But as far as I understand this only "suppresses" the error and I don't know about the consequences.

You can check both fixes on a patched branch of an example repo

Add Apple Privacy file

Starting in April 2024, Apple will require a privacy file. Apple - Privacy manifest files

We must declare the Privacy manifest to be able to deploy to the stores, and this file must contain the code not just from the App but any third-party library we install in our App.

It will be beneficial if we have the Privacy Manifest file in the repo or documentation 🙏

Is this something on the radar? I saw the library install the OpenSSL SDK, which Apple lists in the SDK that requires the privacy file declared.

About upgrade failure?

Hello, if the device is upgraded halfway and Bluetooth is automatically disconnected, causing failure, are there any good optimization items in this area? The nodic app on the official website can search for DfuTarg, and then upgrade it based on the original one.

Trouble reading firmware file

I am experiencing issues reading the firmware files on both IOS and Android. After using RNFS to move the ZIP file, it seems to become totally corrupted on Android (I can't find the file to check it on IOS) (This seems more like an issue with RNFS than this library to me, but I wasn't able to find help there, so I hoped one of you may have encountered it over here and have a solution) and without RNFS, Android has issues reading the manifest file and IOS gives the same error (Error: Firmware not specified) regardless of if I use RNFS.

I will get screenshots and exact errors for all of these cases, but I wanted to put this up here first incase anyone has encountered the same problem and found a solution.

I am running RN 72.6 without expo.

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.