react-native-multi-ble-peripheral
TypeScript icon, indicating that this package has built-in type declarations

0.1.5 • Public • Published

react-native-multi-ble-peripheral

React Native Multi BLE Peripheral Manager

Installation

npm install react-native-multi-ble-peripheral

iOS

Add these lines in Info.plist

<key>NSBluetoothAlwaysUsageDescription</key>
<string>For advertise as BLE peripheral</string>

Android

  • Add these lines in AndroidManifest.xml
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
  • Do this patch if you build on SDK 33+
diff --git a/android/src/main/java/com/fugood/reactnativemultibleperipheral/ReactNativeMultiBlePeripheralModule.kt b/android/src/main/java/com/fugood/reactnativemultibleperipheral/ReactNativeMultiBlePeripheralModule.kt
index 2e763af..746c0c7 100644
--- a/android/src/main/java/com/fugood/reactnativemultibleperipheral/ReactNativeMultiBlePeripheralModule.kt
+++ b/android/src/main/java/com/fugood/reactnativemultibleperipheral/ReactNativeMultiBlePeripheralModule.kt
@@ -241,7 +241,8 @@ class ReactNativeMultiBlePeripheralModule(reactContext: ReactApplicationContext)
       val response = bluetoothGattServer.notifyCharacteristicChanged(
         device,
         characteristic,
-        confirm
+        confirm,
+        value
       )
       Log.d(NAME, "Notify ${device.name} (${device.address}) response = $response")
     }

Request permission

Should check permission before create peripheral instance

import { PermissionsAndroid } from 'react-native';

await PermissionsAndroid.request(
  PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT,
  options,
);
await PermissionsAndroid.request(
  PermissionsAndroid.PERMISSIONS.BLUETOOTH_ADVERTISE,
  options,
);

Usage

import Peripheral, { Permission, Property } from 'react-native-multi-ble-peripheral';
import { Buffer } from 'buffer';

Peripheral.setDeviceName('MyDevice');

const peripheral = new Peripheral();

// We need wait peripheral manager ready before any operation.
peripheral.on('ready', async () => {
  await peripheral.addService('1234', true);
  await peripheral.addCharacteristic(
    '1234',
    'ABCD',
    Property.READ | Property.WRITE,
    Permission.READABLE | Permission.WRITEABLE
  );
  await peripheral.updateValue('1234', 'ABCD', Buffer.from('Hello World!'));
  await peripheral.startAdvertising();
});

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library


Built and maintained by BRICKS.

Package Sidebar

Install

npm i react-native-multi-ble-peripheral

Weekly Downloads

98

Version

0.1.5

License

MIT

Unpacked Size

87.1 kB

Total Files

22

Last publish

Collaborators

  • hans00