📳 Bluetooth Low Energy: The Main Concepts and Difference from Classic Bluetooth
⚙️ 2 Main Libraries for BLE Integration in React Native
⚖ react-native-ble-plx vs react-native-ble-manager Comparison
✅ Apps to Test BLE Devices
⚠️ Possible Pitfalls when Integrating BLE Devices
💡 Takeaways: So, Which One to Choose?
Bluetooth Low Energy (or simply BLE) devices are extremely popular these days. We, at Stormotion, we have already worked on a few projects involving BLE devices: one regarding vaping and another — fitness tracking devices.
In this article, we will specifically focus on the integration of BLE devices in React Native. However, how is this technology different from classic Bluetooth? And what are its key concepts? A brief explanation is below!
We all know what Bluetooth is — a short-range wireless networking protocol that quickly connects devices. Currently, it has 2 versions: Bluetooth Classic and Bluetooth Low Energy.
What are the main terms you need to know when working with this technology? Check below!
Before you move on to the integration of BLE in a React Native App, it’s important to know how this technology works. We won’t focus on that too much but will still review some key concepts.
GATT stands for Generic Attribute Profile that defines how BLE devices transfer data. To make data transfer possible, devices should have a dedicated connection.
BLE devices are often referred to as peripheral devices, while smartphones, tablets, and other similar gadgets — as central devices. Every peripheral device can have an exclusive connection with one central device at a time, while the central device can be simultaneously connected to multiple other peripherals:
Connection between a central and peripheral devices (image by Kevin Townsend)
Since we’re talking about GATT, let’s take a closer look at the server/client relationship:
The Client initiates all the transactions by asking the Server for data. There are 2 ways to transfer data from the Server to the Client: Notifications and Indications.
Data transfer itself is based on a few high-level objects: Profiles, Services, and Characteristics.
The hierarchy of Profiles, Services and Characteristics (image by Kevin Townsend)
Here's an example of how it may look for a fitness tracking device:
Example of Profile structure (image by Mohammad Afaneh)
If we break down the example above into smaller pieces:
Blood Pressure Service
Device Information Service
Intermediate Cuff Pressure
Manufacturer Name String
Nevertheless, let’s get back to today's main topic!
As of July 2020, there are 2 libraries that can be used to integrate BLE devices into your React Native application:
❗️ Important note: this article is based on v.7.3.0 of react-native-ble-manager and v.2.0 of react-native-ble-plx
Let’s take a closer look!
React Native BLE PLX is one of the 2 libraries you can use to work with this technology. It supports all the key features:
Yet, the library doesn’t support the following features:
The new (2.x) version of the library supports all the latest RN versions starting from 0.60. However, you can still use the old version of the library even up to 0.60.5 RN version, but with additional changes.
As for OS versions, the library works on iOS 9+ and Android API 19+.
This library is an alternative option you can use to integrate a BLE device into a React Native application.
Despite the fact that an explicit list of features isn’t provided, we have defined the key functionality based on the names of methods. It includes all the features react-native-ble-plx has and a few additional ones such as:
The latest version of the library supports RN 0.60 and newer. However, the older version of the library can be used with older RN versions:
As for OS versions, this library covers iOS 8+ and Android API 18+.
React Native vs Flutter: Detailed Comparison
We’ve also made a few comparison tables to cover the main differences between the two libraries:
🚀 RN version
🍎 iOS version
🤖 Android version
If we take a look at the features, it's noticeable that react-native-ble-manager provides a bit more possibilities for developers:
observing device's Bluetooth adapter state
scanning BLE devices
making connections to peripherals
observing characteristic notifications/indications
background mode on iOS
turning the device's Bluetooth adapter on
communicating between phones using BLE (Peripheral support)
✅ (Android only)
checking if specific peripheral is connected
getting bonded peripherals
✅ (Android only)
getting connected peripherals
✅ (Android only)
✅ (Android only)
requesting connection priority
✅ (Android API 21+ only)
Written in TypeScript
Finally, we can also compare some GitHub stats:
📊 GitHub Stats (on 12.06.20
👩💻 Used by
In general, react-native-ble-plx is more popular among developers:
When developing a React Native mobile app with BLE integration, you should test how it will actually function with such devices. Our team used the following apps:
These tools are quite similar and provide many options to test different features of BLE devices.
18 Essential Tools For React Native Development
During BLE integration, our developers spotted a few pitfalls that can make the development process a lot trickier. Here are our recommendations on how you can make the development go smoother.
If you’re developing an Android application, this one will be important. As written in this documentation: “Starting from Android API 23+, to access the hardware identifiers of nearby external devices via Bluetooth and Wi-Fi scans, your app must now have the geolocation enabled”.
To check whether the geolocation is enabled and turn it on in case it isn't, we recommend using the react-native-android-location-enabler library.
Obviously, you need to turn on Bluetooth on the device before scanning. For this purpose you may use the methods of the mentioned libraries:
When using react-native-ble-plx, you may stumble upon a bug which will prevent you from being able to change the device name. That can happen in case the name is cached. This issue is tracked here.
Finally, here are a few general tips to improve the code quality:
11 Stories of How React Native Apps Have Changed the World
Simple but true: the best choice is always the one that matches your needs better than all the other options. Thus, we'd recommend you to consider things like:
If you'll find out that both libraries suit you, we’d recommend choosing react-native-ble-plx, as it has a clearer and more structured documentation.
Was it helpful?
How to Integrate BLE-Based Fitness Devices into your App
A Guide to RFID Technology & How It Is Used
How to Integrate a Mobile App Analytics Tool
Our clients say
They understand what it takes to be a great service provider, prioritizing our success over money. I think their approach to addressing ambiguity is their biggest strength. It definitely sets them apart from other remote developers.
Max Scheidlock, Product Manager