Bluetooth Low Energy (BLE). Also called Bluetooth smart, this technology allows peripherals to communicate by consuming much less energy than regular Bluetooth. Another major advantage is that the user does not need to manually pair with the device using the system settings.
Library for BLE react-native-ble-manager
- central (client): phone (search and initiates the connection to the peripheral)
- peripheral (server): heart rate monitor (exposes fields that the central can read, write or be notified)
- advertising: the peripheral sends information to be available to all the centrals around (GAP broadcasting)
- connected: allows a central to exchange data with a peripheral (GATT protocol, one-to-one mode)
- The peripheral exposes fields that the central can read, write or be notified of. Each of these fields is called a characteristic. A characteristic is also accompanied by a descriptor which explains it.
- Characteristics are grouped into a service
- Each characteristic and service is defined by a unique identifier called UUID. There are predefined UUIDs for many services and characteristics. You can find a list here: services and characteristics.
git clone https://github.com/innoveit/react-native-ble-manager
cd react-native-ble-manager
cd example
npm install
react-native link
react-native run-ios
- open
example/androidin android studio - pressed OK in Gradle Sync modal to recreate Gradle properties
- Downgrade Gradle to version 3.5. Edit
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zipingradle-wrapper.properties. - open metro bundler
react-native run-android(ignore error) - run project from android studio on simulator
- app throws warnins about bluetooth
‘No bluetooth support’ (Promise rejection id: 1) ‘PermissionsAndroid.requestPermission’ is deprecated. Use ‘PermissionsAndroid.request’ after press “Scan Bluetooth” or “Retrieve connected peripherals” - new Possible Unhandled Promise Rejection (id: 11)
- delete app from apk
- enable bluetooth on android phone
- run from terminal
cd example adb devices adb -s ES2BA81020000658 reverse tcp:8081 tcp:8081 react-native run-android
react-native docs for signed apk android
-
add
my-release-key.keystoretoandroid/app -
add to
android/gradle.propertiesMYAPP_RELEASE_STORE_FILE=my-release-key.keystore MYAPP_RELEASE_KEY_ALIAS=my-key-alias MYAPP_RELEASE_STORE_PASSWORD=111111 MYAPP_RELEASE_KEY_PASSWORD=111111 -
edit
android/app/build.gradle -
assembleRelease
cd android sudo chmod 755 ./gradlew ./gradlew assembleRelease
clone https://github.com/noble/bleno
cd bleno
npm install
npm install git://github.com/taoyuan/node-xpc-connection.git
cd examples/echo
node main.js
- run android example on device in develpment
-
cd bleno/examples/pizza node peripheral - shake device and open dev tools
- scan bluetooth
- select PizzaSquat android example screen
- check console in dev tools dev tools and peripheral console screen
- example ui video
- central to peripheral connection video
- no robust way to test react-native BLE app with ios simulator or android emulator
- no robust way to connect android with apple peripherals (android phone with apple watch)
- no robust way to setup reliable build and development environments for ios and android (settings, IDEs modules and plugins versions, permissions, packages, etc.)
#492iOS cant connect device after remember device (maintainer can’t help)#456Bluetooth Devices not listing in android (maintainer answer, about android 8 issues with bluetooth)#441IOS | how to read data more than 512 bytes using BLE react native. now we can read only 512 bytes of data (maintainer answer to try notifications)
- https://github.com/Polidea/react-native-ble-plx - maybe hidden marketing of Polidea (hard to setup, use polidea's native rx libraries inside, have link to their landing page)
- BlueCap, interest article about BLE with example
- Core Bluetooth (BLE framework developed by apple and included in the iOS SDK since iOS5)