The React Native Nexstem Companion App Client is a Bluetooth Low Energy (BLE) communication interface for both Android and iOS platforms. It facilitates seamless interaction NexStem headset and also provied abstractions to communicate and experiment ble comm. with headset.
Update your AndroidManifest.xml
file to include the necessary permissions for BLE communication:
<!-- Add xmlns:tools -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="YOUR_PACKAGE_NAME">
<!-- HACK: Permission for BLE on Android 12+ devices -->
<uses-permission android:name="android.permission.BLUETOOTH" tools:remove="android:maxSdkVersion" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" tools:remove="android:maxSdkVersion" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="28"/>
<uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30"/>
<!-- Additional permissions when targeting Android 12 or higher -->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
android:usesPermissionFlags="neverForLocation" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<!-- Include other permissions as needed -->
<!-- ... -->
</manifest>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Your description for Bluetooth usage</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>Your description for Bluetooth peripheral usage</string>
import { BleBasicCustom } from 'react-native-nexstem-companion-app-client';
Initialize BleManger after creating BleBasicCustom instance.
BleBasicCustom.bleManager.start({ showAlert: false });
Create the request to the user to activate the bluetooth. Returns a Promise object.
BleBasicCustom.bleManager.enableBluetooth();
Force the module to check the state of the native BLE manager and trigger a BleManagerDidUpdateState event. Resolves to a promise containing the current BleState.
await BleBasicCustom.bleManager.checkState()
Start the scan and to receive devices pass deviceFoundHandler callback in constructor of BleBasicCustom.scanForDevices
Returns instance of Peripheral which is caught by listener deviceFoundHandler. .
await BleBasicCustom.scanForDevices(5)
Stop the device scan BleBasicCustom.stopScan
await BleBasicCustom.stopScan()
Pair with a device, for IOS ask the use to pair manually from settings.
await BleBasicCustom.pairWithDevice(peripheralId: "")
Gets paired devices, returns a list of Peripherals (instances of peripherals).
await BleBasicCustom.getBondedDevices()
await BleBasicCustom.disconnectDevice(peripheralId: "")
await BleBasicCustom.getDistanceInMetres(peripheralId: "")
BleBasicCustom.cleanup(peripheralId?: string): void
HeadsetManager contains instance of BleBasicCustom, you can use it directly to communicate instead of creating a new BleBasicCustom instance again if you are using HeadsetManager instance.
const headsetManager = new HeadsetManager(handleDeviceFound);
// Methods
// Get CPU Information
headsetManager.getCPUInfo();
// Get Electrode Information
headsetManager.getElectrodeInfo();
// Get Available WiFi Connections
headsetManager.getAvailableWifiConnections();
// Get My WiFi Connections
headsetManager.getMyWifiConnections();
// Connect to WiFi
const ssid = 'your_wifi_ssid';
const password = 'your_wifi_password';
headsetManager.connectToWifi(ssid, password);
// Disconnect from WiFi
headsetManager.disconnectFromWifi();
// Get Settings Device Information
headsetManager.getSettingsDeviceInfo();
// Get Settings Update Information
headsetManager.getSettingsUpdateInfo();
// Get Settings Update Status
headsetManager.getSettingsUpdateStatus();
// Get Battery Percentage
headsetManager.getBatteryPercentage();
headsetManager.events.onBatteryPercentage((data) => {
// Handle battery percentage data
});
headsetManager.events.onElectrodeInfo((data) => {
// Handle electrode information data
});
// Add listeners for other events as needed