https://github.com/mybigday/react-native-multi-ble-peripheral
Multiple BLE Peripheral Manager on React Native
https://github.com/mybigday/react-native-multi-ble-peripheral
beacon ble bluetooth bluetooth-low-energy peripherals react-native
Last synced: about 2 months ago
JSON representation
Multiple BLE Peripheral Manager on React Native
- Host: GitHub
- URL: https://github.com/mybigday/react-native-multi-ble-peripheral
- Owner: mybigday
- License: mit
- Created: 2023-04-25T09:41:26.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-09T09:14:00.000Z (over 1 year ago)
- Last Synced: 2025-03-23T09:48:31.286Z (3 months ago)
- Topics: beacon, ble, bluetooth, bluetooth-low-energy, peripherals, react-native
- Language: Kotlin
- Homepage:
- Size: 477 KB
- Stars: 8
- Watchers: 5
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# react-native-multi-ble-peripheral
React Native Multi BLE Peripheral Manager
## Installation
```sh
npm install react-native-multi-ble-peripheral
```### iOS
Add these lines in `Info.plist`
```xml
NSBluetoothAlwaysUsageDescription
For advertise as BLE peripheral
```### Android
- Add these lines in `AndroidManifest.xml`
```xml
```
- Do this patch if you build on SDK 33+
```diff
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
```js
import { PermissionsAndroid } from 'react-native';await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT,
options,
);
await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.BLUETOOTH_ADVERTISE,
options,
);
```## Usage
```js
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](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
## License
MIT
---
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
---
Built and maintained by BRICKS.