npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-ble-quick-sdk

v0.4.2

Published

A React Native BLE SDK for BDS based ble profile with source autogeneration feature

Downloads

8

Readme

React Native BLE Quick SDK

React Native BLE Customizable SDK for your device's BLE profile, services and characteristics designed using Bluetooth Developer Studio IDE.

Requirements

  • React Native Framework from Facebook
  • Bluetooth Developer Studio IDE from Bluetooth SIG organization
  • BLE profile (xml files) of bluetooth device designed using using Bluetooth Developer Studio.
  • Windows 7/8.1/10 and Mac OS Yosemite/El Capitan/Sierra .

Caution:

This sdk is in development phase so please don't use it for production releases until stable version of this sdk is released.

Supported Platforms

  • React Native 0.35
  • iOS 8+
  • Android to be supported soon.

Install & Prepare


  1. Assuming that Bluetooth Developer Studio is installed and you have created BLE profile for your device using Bluetooth Developer Studio.

  2. Do npm install react-native-ble-quick-sdk as below in your React Native App's root folder. Provide the Bluetooth Developer Studio IDE's root path using argument --bdsPath in npm install command.

 npm install --save react-native-ble-quick-sdk --bdsPath="{Your Bluetooth Developer Studio Installation Folder i.e. C:\Program Files (x86)\Bluetooth SIG\Bluetooth Developer Studio}" 

Note: This step needs admin privilege or it will fail.

  1. Go to terminal, change to directory "{app_project_root}\node_modules\react-native-ble-quick-sdk" and execute below two command sequentially as below:
	a.) npm run generate-ble-profile --bleProfileType="characteristic" --bleNamespace="com.{yourcompanynamespace}" --bdsPrjRootPath="{Your Bluetooth Developer Studio project profile folder i.e. C:\\mybdsprojectpath\\}"

	b.) npm run generate-ble-profile --bleProfileType="service" --bleNamespace="com.{yourcompanynamespace}" --bdsPrjRootPath="{Your Bluetooth Developer Studio project profile folder i.e. C:\\mybdsprojectpath\\}"
  • Note 1:

    Argument-1: bleProfileType is type of BLE profile e.g. service or characteristic. You must run generate-ble-profile command for bleProfileType="characteristic" and again for bleProfileType="service".

    Argument-2: bleNamespace is your BLE device profile's namespace as per Bluetooth Developer Studio.

    Argument-3: bdsPrjRootPath is root folder of your Bluetooth Developer Studio profile project (i.e. where your *.bds file resides). Please note that this is not the root path of your react native app project.

  • Note 2: Please use double slash while specifying path.

Generate BLE device specific API Source


  1. Open your Bluetooth Developer Studio project.

  2. Go to Menu Tools -> Generate Code -> Select "Client" for "Generate Code for" option -> Select Plugin "React Native Client Plugin"

  3. Set output path in "Save To " field to {app_project_root}\node_modules\react-native-ble-quick-sdk.

  4. Press generate button and watch the Bluetooth Developer Studio log window to check if code is generated successfully or not.

  5. If code generation and ble profile generation have completed successfully then React Native BLE Quick SDK is ready to be consumed by BLE Client (Central)react native app to communicate with your BLE device.

Running on iOS (Android not yet supported, To be supported soon )

  • Copy React Native project including \node_modules\react-native-ble-quick-sdk\ from Windows Machine to Mac Machine to prepare and run on iOS.

Link the native library


you need to link the native library. You can either:

  • Link native library with react-native link, or
  • Link native library manually

Both approaches are described below.

Link Native Library with react-native link

react-native link react-native-ble-quick-sdk

Link Native Library Manually

iOS

  • Open the node_modules/react-native-ble-quick-sdk/comm_admins/ble/ios folder and drag RNBluetoothLE.xcodeproj into your Libraries group.
  • Check the "Build Phases"of your project and add "libRNBluetoothLE.a" in the "Link Binary With Libraries" section.

Your Devcie Specific Example


Please refer to folder {app_project_root}\node_modules\react-native-ble-quick-sdk\example\ to find auto generated sample app using this sdk.

Basic Example


** Below example is for for Battery Service as per Bluetooth Specification for type org.bluetooth.service.battery_service(0x180F)


import React, {Component} from 'react'; 
 import { 
     Text, 
     View, 
     Alert, 
     StyleSheet, 
     ScrollView 
 } from 'react-native'; 
 import Button from 'apsl-react-native-button' 
 import {getSDKServiceMgrInstance} from 'react-native-ble-quick-sdk';

 var deviceId = ''; // Assign your device's iOS specific CBUUID here. You can find it in the scan api's console log output by your device name.
 
 var objSDKSvcMgr = getSDKServiceMgrInstance(false);
  
 export default class BLEHelloWorldView extends Component { 

     constructor(props) { 
         super(props); 
     } 

     async scanNearbyBleDevices() { 
			let listenerScan = (deviceID, deviceName, rssi) => {
				console.log(' Device Found iOS CBUUID = ' + deviceID + '/' + deviceName + '[' + rssi + ']');
 			};
         try { 
             await objSDKSvcMgr.getDevAdmin().getDeviceScanner().scanAllServices(5, listenerScan); 
             console.log('Initiated scanning task successfully'); 
         } 
         catch (err) { 
             console.log('Failed to start scanning task'); 
         } 
     } 

     async connect2BleDevice() { 
         try { 
             await objSDKSvcMgr.getDevAdmin().getDeviceAccessor().connectToDevice(deviceId); 
             console.log('device connected'); 
         } 
         catch (err) { 
             console.log('device connection failed'); 
         } 
     } 


     async readBatteryLevel() { 

         let listenerBatteryLevel = (BatteryLevel) => { 
             Alert.alert(' BatteryLevel is ' + BatteryLevel); 
         }; 

         try { 
             await objDevSvcMgr.getService('BatteryService').get_battery_level(listenerBatteryLevel); 
             console.log('readBatteryLevel api call success'); 
         } 
         catch (err) { 
             console.log('readBatteryLevel api call failed'); 
         } 

     } 

     render() { 
         return ( 
             <ScrollView style={styles.page}> 
                 <Text style={styles.tabText}>BLE Hello World </Text> 
                 <Button 
                     style={styles.Button} 
                     onPress={ () => { 
                         this.scanNearbyBleDevices(); 
                     } 
                     }> 
                     1-Scan 
                 </Button> 
                 <Button 
                     style={styles.Button} 
                     onPress={ () => { 
                         this.connect2BleDevice(); 
                     } 
                     }> 
                     2-Connect 
                 </Button> 
                 <Button 
                     style={styles.Button} 
                     onPress={ () => { 
                         this.readBatteryLevel(); 
                     } 
                     }> 
                     3-Read BatteryLevel 
                 </Button> 
             </ScrollView> 
         ); 
     } 
 } 
 var styles = StyleSheet.create({ 
	  page: {
		  backgroundColor: '#edf0f5',
		  flex: 1,
	  }, 
     tabText: { 
         color: 'black', 
         margin: 5, 
    }, 
     Button: { 
         backgroundColor: 'green', 
         margin: 30 
     }, 

 }); 
 

Contributing

If you find any problems, please open an issue or submit a fix as a pull request.

License

Apache License 2.0

Credits

Native part of the project has been borrowed from cordova-plugin-ble-central and react-native-ble-manager. If your react native app project requires to communicate directly with the BLE device at the low level then you should check it out to see if this project React Native BLE Quick SDK or react-native-ble-manager is better fit for you.