Skip to content

Commit c494e9c

Browse files
Merge pull request #106 from ezranbayantemur/master
Update README.md
2 parents b7f0aa4 + 24e70ee commit c494e9c

File tree

1 file changed

+135
-28
lines changed

1 file changed

+135
-28
lines changed

README.md

Lines changed: 135 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,31 @@ Install and link the NPM package per usual with
1111

1212
```bash
1313
npm install --save react-native-nordic-dfu
14+
```
15+
16+
or
17+
18+
```bash
19+
yarn add react-native-nordic-dfu
20+
```
21+
22+
For React Native below 60.0 version
23+
24+
```bash
1425
react-native link react-native-nordic-dfu
1526
```
1627

1728
### Minimum requirements
1829

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

21-
| Dependency | Version |
22-
|-|-|
23-
| React Native | 0.59.4 |
24-
| XCode | 10.2 |
25-
| Swift | 5.0 |
26-
| CocoaPods | 1.6.1 |
27-
| Gradle | 5.3.1 |
32+
| Dependency | Version |
33+
| ------------ | ------- |
34+
| React Native | 0.59.4 |
35+
| XCode | 10.2 |
36+
| Swift | 5.0 |
37+
| CocoaPods | 1.6.1 |
38+
| Gradle | 5.3.1 |
2839

2940
### iOS
3041

@@ -34,16 +45,23 @@ Previous versions supported manual linking, but this was prone to errors every t
3445

3546
#### CocoaPods
3647

48+
On your project directory;
49+
50+
```bash
51+
cd ios && pod install
52+
```
53+
54+
If your React Native version below 0.60 or any problem occures on pod command, you can try these steps;
55+
3756
Add the following to your `Podfile`
3857

3958
```ruby
4059
target "YourApp" do
60+
4161
...
42-
43-
use_frameworks!
4462
pod "react-native-nordic-dfu", path: "../node_modules/react-native-nordic-dfu"
45-
4663
...
64+
4765
end
4866
```
4967

@@ -55,6 +73,8 @@ pod install
5573

5674
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>`.
5775

76+
If your React Native version is higher than 0.60, probably it's already there.
77+
5878
#### Bluetooth integration
5979

6080
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.
@@ -63,7 +83,50 @@ To integrate with your existing Bluetooth setup, call `[RNNordicDfu setCentralMa
6383

6484
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.
6585

66-
The example project shows how this may be done.
86+
Example code;
87+
88+
```swift
89+
...
90+
...
91+
#import "RNNordicDfu.h"
92+
#import "BleManager.h"
93+
94+
@implementation AppDelegate
95+
96+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
97+
...
98+
...
99+
100+
[RNNordicDfu setCentralManagerGetter:^() {
101+
return [BleManager getCentralManager];
102+
}];
103+
104+
// Reset manager delegate since the Nordic DFU lib "steals" control over it
105+
[RNNordicDfu setOnDFUComplete:^() {
106+
NSLog(@"onDFUComplete");
107+
CBCentralManager * manager = [BleManager getCentralManager];
108+
manager.delegate = [BleManager getInstance];
109+
}];
110+
111+
[RNNordicDfu setOnDFUError:^() {
112+
NSLog(@"onDFUError");
113+
CBCentralManager * manager = [BleManager getCentralManager];
114+
manager.delegate = [BleManager getInstance];
115+
}];
116+
117+
return YES;
118+
}
119+
120+
```
121+
122+
You can find them aslo in example project.
123+
124+
On iOS side this library requires to BleManager module which that [react-native-ble-manager](https://github.com/innoveit/react-native-ble-manager) provides.
125+
126+
It required because;
127+
128+
- You need `BleManager.h` module on AppDelegate file for integration.
129+
- 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).
67130

68131
### Android
69132

@@ -89,11 +152,11 @@ done in React Native.
89152

90153
**Parameters**
91154

92-
- `obj` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
93-
- `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
94-
- `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`)
95-
- `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
96-
- `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`
155+
- `obj` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
156+
- `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
157+
- `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`)
158+
- `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
159+
- `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`
97160

98161
\* `identifier` — MAC address (Android) / UUID (iOS)
99162

@@ -105,9 +168,9 @@ import { NordicDFU, DFUEmitter } from "react-native-nordic-dfu";
105168
NordicDFU.startDFU({
106169
deviceAddress: "C3:53:C0:39:2F:99",
107170
deviceName: "Pilloxa Pillbox",
108-
filePath: "/data/user/0/com.nordicdfuexample/files/RNFetchBlobTmp4of.zip"
171+
filePath: "/data/user/0/com.nordicdfuexample/files/RNFetchBlobTmp4of.zip",
109172
})
110-
.then(res => console.log("Transfer done:", res))
173+
.then((res) => console.log("Transfer done:", res))
111174
.catch(console.log);
112175
```
113176

@@ -122,15 +185,59 @@ Event emitter for DFU state and progress events
122185
```javascript
123186
import { NordicDFU, DFUEmitter } from "react-native-nordic-dfu";
124187

125-
DFUEmitter.addListener("DFUProgress",({percent, currentPart, partsTotal, avgSpeed, speed}) => {
126-
console.log("DFU progress: " + percent +"%");
127-
});
188+
DFUEmitter.addListener(
189+
"DFUProgress",
190+
({ percent, currentPart, partsTotal, avgSpeed, speed }) => {
191+
console.log("DFU progress: " + percent + "%");
192+
}
193+
);
128194

129-
DFUEmitter.addListener("DFUStateChanged", ({state}) => {
195+
DFUEmitter.addListener("DFUStateChanged", ({ state }) => {
130196
console.log("DFU State:", state);
131-
})
197+
});
198+
```
199+
200+
## Selecting firmware file from local storage
201+
202+
If your user will select the firmware file from local storage you should keep on mind some issues;
203+
204+
You can use [react-native-document-picker](https://github.com/Elyx0/react-native-document-picker) library for file selecting process.
205+
206+
### On iOS
207+
208+
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)
209+
210+
```js
211+
DocumentPicker.pick({ type: "public.archive" });
132212
```
133213

214+
If your device getting disconnect after enable DFU, you should set `false` value to `alternativeAdvertisingNameEnabled` prop while starting DFU.
215+
216+
```js
217+
NordicDFU.startDFU({
218+
deviceAddress: "XXXXXXXX-XXXX-XXXX-XXXX-XX",
219+
filePath: firmwareFile.uri,
220+
alternativeAdvertisingNameEnabled: false,
221+
});
222+
```
223+
224+
### On Android
225+
226+
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.
227+
228+
You can use [react-native-fs](https://github.com/itinance/react-native-fs) for copying file.
229+
230+
```js
231+
const firmwareFile = await DocumentPicker.pick({ type: DocumentPicker.types.zip })
232+
const destination = RNFS.CachesDirectoryPath + "/firmwareFile.zip");
233+
234+
await RNFS.copyFile(formatFile.uri, destination);
235+
236+
NordicDFU.startDFU({ deviceAddress: "XX:XX:XX:XX:XX:XX", filePath: destination })
237+
```
238+
239+
If you getting disconnect error sometimes while starting DFU process, you should connect the device before start it.
240+
134241
## Example project
135242

136243
Navigate to `example/` and run
@@ -157,11 +264,11 @@ PR's are always welcome!
157264

158265
## Resources
159266

160-
- [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")
161-
- [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")
162-
- [How to create init packet](https://github.com/NordicSemiconductor/Android-nRF-Connect/tree/master/init%20packet%20handling "Init packet handling")
163-
- [nRF51 Development Kit (DK)](http://www.nordicsemi.com/eng/Products/nRF51-DK "nRF51 DK") (compatible with Arduino Uno Revision 3)
164-
- [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)
267+
- [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")
268+
- [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")
269+
- [How to create init packet](https://github.com/NordicSemiconductor/Android-nRF-Connect/tree/master/init%20packet%20handling "Init packet handling")
270+
- [nRF51 Development Kit (DK)](http://www.nordicsemi.com/eng/Products/nRF51-DK "nRF51 DK") (compatible with Arduino Uno Revision 3)
271+
- [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)
165272

166273
## Sponsored by
167274

0 commit comments

Comments
 (0)