author: Olha Maksymets
publication date: Jul 12, 2024
Our developer Oleksandr successfully connected scales to the Healthcare app using Bluetooth Low Energy (BLE) technology. In this article, we'll look at the features of BLE, the challenges Oleksandr faced, and the solutions used.
There are two main types of Bluetooth challenges:
BLE has standards that simplify the process for devices. Device manufacturers adhering to these standards ensure that any smartphone can connect to it. If a device does not meet the standards, app developers must write additional code to connect it.
The scale that Oleksandr connected did not comply with the BLE standards. The manufacturer of the scales provided documentation describing the process of correctly reading the data and interpreting the current readings. Oleksandr's main task was to use this documentation to retrieve and correctly display the weight values.
To implement the connection to BLE devices in a React Native application, Oleksandr used the react-native-ble-plx library. This library provides all the necessary functions to scan, connect and interact with BLE devices.
import { BleManager } from 'react-native-ble-plx';
export const manager = new BleManager();
Creating a single instance of BleManager
allows you to manage all BLE operations.
In order for BLE to work correctly, the application must request location permissions from the user. This allows the application to determine if the device is within range to connect.
async function requestLocationPermission() {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: "Location Access Required",
message: "This app needs to access your location to detect Bluetooth devices",
}
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log("Location permission granted");
} else {
console.log("Location permission denied");
}
} catch (err) {
console.warn(err);
}
}
Through the efforts of our developer and utilizing the documentation provided, the scale has been successfully integrated with the Healthcare app. This allows users to conveniently and accurately read weight readings through the app, providing better control over their health. The use of React Native BLE PLX and proper management of location permissions made this process efficient and reliable.