### Install react-native-ble-peripheral Source: https://github.com/himelbrand/react-native-ble-peripheral/blob/master/README.md Installs the react-native-ble-peripheral package using either npm or yarn. ```bash npm install react-native-ble-peripheral --save or yarn add react-native-ble-peripheral ``` -------------------------------- ### Start BLE Advertising Source: https://github.com/himelbrand/react-native-ble-peripheral/blob/master/README.md Starts the BLE advertising process. This should be called after adding services and characteristics. Includes promise-based handling for success and errors. ```javascript BLEPeripheral.start() .then(res => { console.log(res) }).catch(error => { console.log(error) }) ``` -------------------------------- ### Set BLE Device Name Source: https://github.com/himelbrand/react-native-ble-peripheral/blob/master/README.md Sets the broadcast name for the BLE peripheral device before starting advertising. ```javascript BLEPeripheral.setName('RNBLETEST') ``` -------------------------------- ### Configure Android Project (Manual) Source: https://github.com/himelbrand/react-native-ble-peripheral/blob/master/README.md Manually configures the Android project to include the react-native-ble-peripheral library by updating settings.gradle and build.gradle files. ```gradle android/settings.gradle: ... include ':react-native-ble-peripheral' project(':react-native-ble-peripheral').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-ble-peripheral/android') android/app/build.gradle: ... dependencies { /* YOUR DEPENDENCIES HERE */ compile project(':react-native-ble-peripheral') // <--- add this } ``` -------------------------------- ### Link react-native-ble-peripheral (Auto) Source: https://github.com/himelbrand/react-native-ble-peripheral/blob/master/README.md Automatically links the react-native-ble-peripheral library to the React Native project. ```bash react-native link ``` -------------------------------- ### Import BLEPeripheral Module Source: https://github.com/himelbrand/react-native-ble-peripheral/blob/master/README.md Imports the BLEPeripheral module from the 'react-native-ble-peripheral' library in JavaScript. ```javascript import BLEPeripheral from 'react-native-ble-peripheral' ``` -------------------------------- ### Register Native Module (Java) Source: https://github.com/himelbrand/react-native-ble-peripheral/blob/master/README.md Registers the RNBLEPackage native module in the MainActivity.java file for Android. ```java import com.himelbrand.forwardcalls.RNForwardCallsPackage; // <--- import public class MainActivity extends ReactActivity { ...... @Override protected List getPackages() { return Arrays.asList( new MainReactPackage(), new RNBLEPackage() // <--- Add this ); } ...... } ``` -------------------------------- ### Add Android Bluetooth Permissions Source: https://github.com/himelbrand/react-native-ble-peripheral/blob/master/README.md Adds necessary Bluetooth permissions to the AndroidManifest.xml file for BLE functionality. ```xml ``` -------------------------------- ### Add BLE Service Source: https://github.com/himelbrand/react-native-ble-peripheral/blob/master/README.md Adds a BLE service to the peripheral. Services are identified by UUIDs and can be primary or secondary. ```javascript BLEPeripheral.addService('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX', true) //for primary service BLEPeripheral.addService('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX', false) //for non primary service ``` -------------------------------- ### Add BLE Characteristic Source: https://github.com/himelbrand/react-native-ble-peripheral/blob/master/README.md Adds a characteristic to a specified BLE service. Requires service UUID, characteristic UUID, permissions, and properties. ```javascript BLEPeripheral.addCharacteristicToService('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX', 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX', 16 | 1, 8) //this is a Characteristic with read and write permissions and notify property ``` -------------------------------- ### Stop BLE Advertising Source: https://github.com/himelbrand/react-native-ble-peripheral/blob/master/README.md Stops the BLE advertising process. ```javascript BLEPeripheral.stop() ``` -------------------------------- ### Send BLE Notification Source: https://github.com/himelbrand/react-native-ble-peripheral/blob/master/README.md Sends a notification to all connected devices for a specific characteristic. The data should be an array of numbers representing bytes. ```javascript BLEPeripheral.sendNotificationToDevices('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX', 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX', [0x10,0x01,0xA1,0x80]) //sends a notification to all connected devices that, using the char uuid given ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.