Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update XCode 13 & Android 12 #164

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
cf63c4b
Add XCode 13 support & Fix Android module
manualexSP Jan 13, 2022
c722d69
Update ios platform Version
manualexSP Jan 13, 2022
00ce741
Update Android 12
manualexSP Mar 29, 2022
d72c214
Update README
manualexSP May 5, 2022
6593dd2
Bump version
manualexSP May 5, 2022
de2bf33
fix: use androidx
anees17861 Nov 10, 2022
9ca23e4
Merge pull request #1 from anees17861/fix/androidx
manualexSP Nov 25, 2022
40fdaa9
RNNDFU: Update Nordic Android & iOS dependencies
manualexSP Jan 21, 2023
894dafb
RNNDFU: Update Breaking changes ios
manualexSP Jan 21, 2023
a231f8d
RNNDFU: Revert changes & downgrade ios to 4.12.0
manualexSP Jan 21, 2023
b720d3d
Merge pull request #2 from Salt-PepperEngineering/update-nordic-platf…
manualexSP Jan 29, 2023
b3604a3
Update README.md
moonbird-yordi Feb 8, 2023
c72823d
Merge pull request #3 from moonbird-yordi/patch-1
manualexSP Feb 22, 2023
7db7e53
Update xcode dependencies
manualexSP Jun 26, 2023
838a46a
Update iOSDFULibrary 4.13.0
manualexSP Jun 28, 2023
dbc6d98
Update README & add some old PR from Pilloxa
manualexSP Jun 28, 2023
a7df6b2
Revert ios min version to 8
manualexSP Jun 28, 2023
bbcbadd
Add back mtu and retries capabilities for android
manualexSP Jun 28, 2023
4ffc30e
Add back mtu and retries capabilities for android
manualexSP Jun 28, 2023
86b1c2c
Merge pull request #6 from Salt-PepperEngineering/update-xcode
manualexSP Jun 28, 2023
cd33d36
Update Pod config README
aluxmanu Jul 5, 2023
fc3af9a
Update README
aluxmanu Jul 7, 2023
a592bef
Create new Example folder & setup nordic-dfu
aluxmanu Jul 7, 2023
4757f01
Add new updated example
aluxmanu Jul 7, 2023
70d6af9
Update README
aluxmanu Jul 7, 2023
8f1aa5c
Revert dependencies
aluxmanu Jul 7, 2023
910a1a7
Merge pull request #7 from Salt-PepperEngineering/newExample
manualexSP Jul 7, 2023
2ca79f8
add addListner
Jul 12, 2023
6687387
Merge pull request #9 from saileshkasaju/master
manualexSP Jul 20, 2023
ac79086
Add android 14 support
niklavsBariss May 9, 2024
5debe99
Merge pull request #18 from mitigate-dev/fix/android-14
manualexSP Jun 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
276 changes: 67 additions & 209 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@ nrf52 chip from Nordic Semiconductor. It works for both iOS and Android.

For more info about the DFU process, see: [Resources](#resources)

## Installation
### 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](https://github.com/Pilloxa/react-native-nordic-dfu).
- This fork contains the latest verisons of `iOSDFULibrary` & `Android-BLE-Library`.

### Installation

Install and link the NPM package per usual with

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

or

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

For React Native below 60.0 version
Expand All @@ -25,251 +31,103 @@ For React Native below 60.0 version
react-native link react-native-nordic-dfu
```

### Minimum requirements

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

| Dependency | Version |
| ------------ | ------- |
| React Native | 0.59.4 |
| XCode | 10.2 |
| Swift | 5.0 |
| CocoaPods | 1.6.1 |
| Gradle | 5.3.1 |
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.

### iOS
`Podfile`:

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!)
- Flipper Disabled

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
```ruby
target "YourApp" do

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

```bash
cd ios && pod install
end
```

If your React Native version below 0.60 or any problem occures on pod command, you can try these steps;

Add the following to your `Podfile`
- Flipper enabled

```ruby
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
```

and in the same folder as the Podfile run
`AppDelegate.mm`:

```bash
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>`.

If your React Native version is higher than 0.60, probably it's already there.

#### 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.

To integrate with your existing Bluetooth setup, call `[RNNordicDfu setCentralManagerGetter:<...>]` with a block argument that returns your `CBCentralManager` instance.

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.

Example code;

```swift
...
...
#import "RNNordicDfu.h"
#import "BleManager.h"
...

@implementation AppDelegate

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

[RNNordicDfu setCentralManagerGetter:^() {
return [BleManager getCentralManager];
}];

// Reset manager delegate since the Nordic DFU lib "steals" control over it
[RNNordicDfu setOnDFUComplete:^() {
NSLog(@"onDFUComplete");
CBCentralManager * manager = [BleManager getCentralManager];
manager.delegate = [BleManager getInstance];
}];

[RNNordicDfu setOnDFUError:^() {
NSLog(@"onDFUError");
CBCentralManager * manager = [BleManager getCentralManager];
manager.delegate = [BleManager getInstance];
}];
[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");
}];
...

return YES;
}

```

You can find them aslo in example project.

On iOS side this library requires to BleManager module which that [react-native-ble-manager](https://github.com/innoveit/react-native-ble-manager) provides.

It required because;

- You need `BleManager.h` module on AppDelegate file for integration.
- You should call `BleManager.start()` (for once) before the trigger a DFU process on iOS or you will get error like [this issue](https://github.com/Pilloxa/react-native-nordic-dfu/issues/82).

### Android

Android requires that you have `FOREGROUND_SERVICE` permissions.
You will need the following in your AndroidManifest.xml

```
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
```

## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### 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**
### New Example

- `obj` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `obj.deviceAddress` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The `identifier`\* of the device that should be updated
- `obj.deviceName` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the device in the update notification (optional, default `null`)
- `obj.filePath` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The file system path to the zip-file used for updating
- `obj.alternativeAdvertisingNameEnabled` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Send unique name to device before it is switched into bootloader mode (iOS only) - defaults to `true`
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](https://github.com/innoveit/react-native-ble-manager)

\* `identifier` — MAC address (Android) / UUID (iOS)
### Issues

**Examples**
- For configuration issues please also check this (https://github.com/Pilloxa/react-native-nordic-dfu/issues/171)

```javascript
import { NordicDFU, DFUEmitter } from "react-native-nordic-dfu";

NordicDFU.startDFU({
deviceAddress: "C3:53:C0:39:2F:99",
deviceName: "Pilloxa Pillbox",
filePath: "/data/user/0/com.nordicdfuexample/files/RNFetchBlobTmp4of.zip",
})
.then((res) => console.log("Transfer done:", res))
.catch(console.log);
```

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** A promise that resolves or rejects with the `deviceAddress` in the return value

### DFUEmitter

Event emitter for DFU state and progress events

**Examples**

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

## Selecting firmware file from local storage

If your user will select the firmware file from local storage you should keep on mind some issues;

You can use [react-native-document-picker](https://github.com/Elyx0/react-native-document-picker) library for file selecting process.

### On iOS

You should select file type as `public.archive` or you will get null type error as like [this issue](https://github.com/Pilloxa/react-native-nordic-dfu/issues/100)

```js
DocumentPicker.pick({ type: "public.archive" });
```

If your device getting disconnect after enable DFU, you should set `false` value to `alternativeAdvertisingNameEnabled` prop while starting DFU.

```js
NordicDFU.startDFU({
deviceAddress: "XXXXXXXX-XXXX-XXXX-XXXX-XX",
filePath: firmwareFile.uri,
alternativeAdvertisingNameEnabled: false,
});
```

### On Android

Some Android versions directly selecting file may can cause errors. If you get any file error you should copy it to your local storage. Like cache directory.

You can use [react-native-fs](https://github.com/itinance/react-native-fs) for copying file.

```js
const firmwareFile = await DocumentPicker.pick({ type: DocumentPicker.types.zip })
const destination = RNFS.CachesDirectoryPath + "/firmwareFile.zip");

await RNFS.copyFile(formatFile.uri, destination);

NordicDFU.startDFU({ deviceAddress: "XX:XX:XX:XX:XX:XX", filePath: destination })
```

If you getting disconnect error sometimes while starting DFU process, you should connect the device before start it.

## Example project

Navigate to `example/` and run

```bash
npm install
```

Run the iOS project with

```bash
react-native run-ios
```

and the Android project with

```bash
react-native run-android
```

## Development

PR's are always welcome!

## Resources
### Resources

- [DFU Introduction](http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v11.0.0/examples_ble_dfu.html?cp=6_0_0_4_3_1 "BLE Bootloader/DFU")
- [Secure DFU Introduction](http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v12.0.0/ble_sdk_app_dfu_bootloader.html?cp=4_0_0_4_3_1 "BLE Secure DFU Bootloader")
- [How to create init packet](https://github.com/NordicSemiconductor/Android-nRF-Connect/tree/master/init%20packet%20handling "Init packet handling")
- [nRF51 Development Kit (DK)](http://www.nordicsemi.com/eng/Products/nRF51-DK "nRF51 DK") (compatible with Arduino Uno Revision 3)
- [nRF52 Development Kit (DK)](http://www.nordicsemi.com/eng/Products/Bluetooth-Smart-Bluetooth-low-energy/nRF52-DK "nRF52 DK") (compatible with Arduino Uno Revision 3)

## Sponsored by

[![pilloxa](https://pilloxa.com/images/pilloxa-round-logo.svg)](https://pilloxa.com)
14 changes: 7 additions & 7 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@

buildscript {
repositories {
jcenter()
mavenCentral()
google()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath("com.android.tools.build:gradle:7.2.1")
}
}

apply plugin: 'com.android.library'

def DEFAULT_COMPILE_SDK_VERSION = 28
def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3'
def DEFAULT_TARGET_SDK_VERSION = 26
def DEFAULT_COMPILE_SDK_VERSION = 31
def DEFAULT_BUILD_TOOLS_VERSION = '31.0.0'
def DEFAULT_TARGET_SDK_VERSION = 31

android {
compileSdkVersion project.hasProperty('compileSdkVersion') ? project.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
Expand All @@ -38,6 +38,6 @@ repositories {

dependencies {
implementation 'com.facebook.react:react-native:+'
implementation 'no.nordicsemi.android:dfu:1.8.0'
implementation 'no.nordicsemi.android:dfu:2.4.2'
}

15 changes: 15 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Sat Jan 21 13:51:07 EET 2023
android.useAndroidX=true
android.enableJetifier=true
7 changes: 3 additions & 4 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#Wed Nov 28 15:32:55 CET 2018
#Sat Jan 21 14:00:10 EET 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

zipStoreBase=GRADLE_USER_HOME
Loading