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

Create New example project #7

Merged
merged 4 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ end
- Flipper enabled

```ruby
static_frameworks = ['iOSDFULibrary']
static_frameworks = ['iOSDFULibrary']
pre_install do |installer|
installer.pod_targets.each do |pod|
if static_frameworks.include?(pod.name)
Expand Down Expand Up @@ -109,6 +109,17 @@ end
}
```

### 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](https://github.com/innoveit/react-native-ble-manager)

### Issues

- For configuration issues please also check this (https://github.com/Pilloxa/react-native-nordic-dfu/issues/171)
Expand Down
2 changes: 2 additions & 0 deletions newExample/.bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BUNDLE_PATH: "vendor/bundle"
BUNDLE_FORCE_RUBY_PLATFORM: 1
4 changes: 4 additions & 0 deletions newExample/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: '@react-native',
};
66 changes: 66 additions & 0 deletions newExample/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# OSX
#
.DS_Store

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
ios/.xcode.env.local

# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml
*.hprof
.cxx/
*.keystore
!debug.keystore

# node.js
#
node_modules/
npm-debug.log
yarn-error.log

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/

**/fastlane/report.xml
**/fastlane/Preview.html
**/fastlane/screenshots
**/fastlane/test_output

# Bundle artifact
*.jsbundle

# Ruby / CocoaPods
/ios/Pods/
/vendor/bundle/

# Temporary files created by Metro to check the health of the file watcher
.metro-health-check*

# testing
/coverage
7 changes: 7 additions & 0 deletions newExample/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
arrowParens: 'avoid',
bracketSameLine: true,
bracketSpacing: false,
singleQuote: true,
trailingComma: 'all',
};
1 change: 1 addition & 0 deletions newExample/.watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
130 changes: 130 additions & 0 deletions newExample/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import React, {useEffect, useState} from 'react';
import {
PermissionsAndroid,
Platform,
StyleSheet,
Text,
TouchableOpacity,
View,
} from 'react-native';
import {BleManagerService} from './src/BleService';
import {Peripheral} from 'react-native-ble-manager';
import {NordicDFU, DFUEmitter} from 'react-native-nordic-dfu';
import ReactNativeBlobUtil from 'react-native-blob-util';
import RNFS from 'react-native-fs';

const styles = StyleSheet.create({
container: {
backgroundColor: 'white',
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
buttonContainer: {
height: 40,
width: 200,
borderWidth: 1,
borderRadius: 10,
alignItems: 'center',
justifyContent: 'center',
marginTop: 100,
backgroundColor: '#F98234',
},
deviceContainer: {
alignItems: 'center',
justifyContent: 'space-evenly',
height: 100,
width: 200,
borderWidth: 1,
borderRadius: 10,
marginTop: 200,
},
text: {
color: 'black',
},
});

const App: React.FC = () => {
const [device, setDevice] = useState<Peripheral>();
const [percentage, setPercentage] = useState(0);
const filePath = '';

useEffect(() => {
PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT,
PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN,
PermissionsAndroid.PERMISSIONS.BLUETOOTH_ADVERTISE,
]);
BleManagerService.init('', '');
}, []);

const onPressConnectDevice = async () => {
try {
const connectedDevice = await BleManagerService.scanAndConnectToDevice();
console.log('Connected -->', connectedDevice);
setDevice(connectedDevice as Peripheral);
} catch (error) {
return console.log(error);
}
};

const uploadToDevice = async (filePath: string) => {
if (!device) {
return console.log('No Device');
}

const destination = `${RNFS.DocumentDirectoryPath}/installationFile.zip`;
const exists = await RNFS.exists(destination);
exists && (await RNFS.unlink(destination));
const response = await ReactNativeBlobUtil.config({
fileCache: true,
appendExt: 'zip',
}).fetch('GET', filePath);

const downloadPath = response.path();
await RNFS.copyFile(downloadPath, destination);
response?.flush();

DFUEmitter.addListener('DFUProgress', ({percent}) => {
percent && setPercentage(percent);
});
return NordicDFU.startDFU({
deviceAddress: device.id,
deviceName: device.name,
filePath: Platform.OS === 'ios' ? `file://${destination}` : destination,
})
.then(() => {
console.log('Done');
})
.catch(err => {
console.log('DFU', err);
DFUEmitter.removeAllListeners('DFUProgress');
return Promise.reject(err);
});
};

return (
<View style={styles.container}>
<Text style={styles.text}>{'New Example Nordic DFU'}</Text>
<View style={styles.deviceContainer}>
<Text style={styles.text}>{device?.name}</Text>
<Text style={styles.text}>{device?.id}</Text>
<Text style={styles.text}>{percentage}</Text>
</View>
<TouchableOpacity
style={styles.buttonContainer}
onPress={onPressConnectDevice}>
<Text>{'Connect to Device in Area'}</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.buttonContainer}
onPress={() => {
uploadToDevice(filePath);
}}>
<Text>{'Start Update'}</Text>
</TouchableOpacity>
</View>
);
};

export default App;
6 changes: 6 additions & 0 deletions newExample/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source 'https://rubygems.org'

# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
ruby ">= 2.6.10"

gem 'cocoapods', '~> 1.12'
100 changes: 100 additions & 0 deletions newExample/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
GEM
remote: https://rubygems.org/
specs:
CFPropertyList (3.0.6)
rexml
activesupport (6.1.7.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
addressable (2.8.4)
public_suffix (>= 2.0.2, < 6.0)
algoliasearch (1.27.5)
httpclient (~> 2.8, >= 2.8.3)
json (>= 1.5.1)
atomos (0.1.3)
claide (1.1.0)
cocoapods (1.12.1)
addressable (~> 2.8)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.12.1)
cocoapods-deintegrate (>= 1.0.3, < 2.0)
cocoapods-downloader (>= 1.6.0, < 2.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
cocoapods-search (>= 1.0.0, < 2.0)
cocoapods-trunk (>= 1.6.0, < 2.0)
cocoapods-try (>= 1.1.0, < 2.0)
colored2 (~> 3.1)
escape (~> 0.0.4)
fourflusher (>= 2.3.0, < 3.0)
gh_inspector (~> 1.0)
molinillo (~> 0.8.0)
nap (~> 1.0)
ruby-macho (>= 2.3.0, < 3.0)
xcodeproj (>= 1.21.0, < 2.0)
cocoapods-core (1.12.1)
activesupport (>= 5.0, < 8)
addressable (~> 2.8)
algoliasearch (~> 1.0)
concurrent-ruby (~> 1.1)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
netrc (~> 0.11)
public_suffix (~> 4.0)
typhoeus (~> 1.0)
cocoapods-deintegrate (1.0.5)
cocoapods-downloader (1.6.3)
cocoapods-plugins (1.0.0)
nap
cocoapods-search (1.0.1)
cocoapods-trunk (1.6.0)
nap (>= 0.8, < 2.0)
netrc (~> 0.11)
cocoapods-try (1.2.0)
colored2 (3.1.2)
concurrent-ruby (1.2.2)
escape (0.0.4)
ethon (0.16.0)
ffi (>= 1.15.0)
ffi (1.15.5)
fourflusher (2.3.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
httpclient (2.8.3)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
json (2.6.3)
minitest (5.18.1)
molinillo (0.8.0)
nanaimo (0.3.0)
nap (1.1.0)
netrc (0.11.0)
public_suffix (4.0.7)
rexml (3.2.5)
ruby-macho (2.5.1)
typhoeus (1.4.0)
ethon (>= 0.9.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
xcodeproj (1.22.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.3.0)
rexml (~> 3.2.4)
zeitwerk (2.6.8)

PLATFORMS
ruby

DEPENDENCIES
cocoapods (~> 1.12)

RUBY VERSION
ruby 2.6.10p210

BUNDLED WITH
2.3.24
Loading