react-native-nexstem-companion-app-client
v2.2.17
Published
This is a package to communicate with nexstem headset via ble
Downloads
63
Maintainers
Readme
React Native Nexstem Companion App Client
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.
Permissions and Manifest Updates
Android Manifest Updates
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>
IOS podfile Updates
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Your description for Bluetooth usage</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>Your description for Bluetooth peripheral usage</string>
Usage
Import the library
import { BleBasicCustom } from 'react-native-nexstem-companion-app-client';
Initialize BleManger
Initialize BleManger after creating BleBasicCustom instance.
BleBasicCustom.bleManager.start({ showAlert: false });
Enable Bluetooth [Android Only]
Create the request to the user to activate the bluetooth. Returns a Promise object.
BleBasicCustom.bleManager.enableBluetooth();
Check Bluetooth State
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 device scan
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 device scan
Stop the device scan BleBasicCustom.stopScan
await BleBasicCustom.stopScan()
Pair with device [Android Only]
Pair with a device, for IOS ask the use to pair manually from settings.
await BleBasicCustom.pairWithDevice(peripheralId: "")
Get Paired Devices [Android Only]
Gets paired devices, returns a list of Peripherals (instances of peripherals).
await BleBasicCustom.getBondedDevices()
Disconnect from Device
await BleBasicCustom.disconnectDevice(peripheralId: "")
Get distance from Device
await BleBasicCustom.getDistanceInMetres(peripheralId: "")
Perform a cleanup before reinitializing BleBasicCustom class.
BleBasicCustom.cleanup(peripheralId?: string): void
Note
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.
Headset Manager Initialization
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();
Headset Event Handling
headsetManager.events.onBatteryPercentage((data) => {
// Handle battery percentage data
});
headsetManager.events.onElectrodeInfo((data) => {
// Handle electrode information data
});
// Add listeners for other events as needed