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

dirox-react-native-ble-peripheral

v1.0.5

Published

Native BLE Peripheral in React Native

Downloads

3

Readme

dirox-react-native-ble-peripheral

This is a simulator for a BLE peripheral, to help with testing BLE apps without an actual peripheral BLE device this project is not yet complete, for all ready parts see documentation below. (docs are not complete, feel free to improve them)

Installation

npm install dirox-react-native-ble-peripheral

Usage

0. Import package to project

import DiroxReactNativeBlePeripheral from 'dirox-react-native-ble-peripheral';

// ...

Methods

1. checkPermissions

let permissionStatus = await DiroxReactNativeBlePeripheral.checkPermissions(["android.permission.BLUETOOTH", "android.permission.ACCESS_FINE_LOCATION"])
permissionStatus['android.permission.BLUETOOTH']              //  UNAVAILABLE | BLOCKED | DENIED | GRANTED | LIMITED
permissionStatus['android.permission.ACCESS_FINE_LOCATION']   //  UNAVAILABLE | BLOCKED | DENIED | GRANTED | LIMITED

2. requestPermissions

await DiroxReactNativeBlePeripheral.requestPermissions(["android.permission.BLUETOOTH", "android.permission.ACCESS_FINE_LOCATION"])

3. createService

await DiroxReactNativeBlePeripheral.createService(uuid: String, serviceType: int<SERVICE_TYPE_ENUM>)
SERVICE_TYPE_ENUM:
 - PRIMARY = 0
 - SECONDARY = 1 
Example:
 let dataService = await DiroxReactNativeBlePeripheral.createService('9b1deb4d-1bdd-1bdd-1bdd-2b0d7b3dcb6d', 0)

ADD_LISTENER
import { DeviceEventEmitter} from 'react-native';

DeviceEventEmitter.addListener('onCharacteristicReadRequest', event => {
    console.log("onCharacteristicReadRequest call: ", event.uuid)
});
DeviceEventEmitter.addListener('onCharacteristicWriteRequest', event => {
    console.log(`onCharacteristicWriteRequest: ${event.uuid} , ${event.value}, ${event.deviceAddress}, ${event.requestId}`)
});
DeviceEventEmitter.addListener('bluetoothDeviceConnected', event => {
    console.log(`bluetoothDeviceConnected: ${event.deviceAddress}`)
});
DeviceEventEmitter.addListener('bluetoothDeviceDisconnected', event => {
    console.log(`bluetoothDeviceDisconnected: ${event.deviceAddress}`)
});

STOP_LISTENER
DeviceEventEmitter.removeAllListeners()

UUID (String) to Bytes (hex String)
let bytes = await DiroxReactNativeBlePeripheral.getBytesFromUUID('your uuid')

Bytes (hex String) to UUID (String)
let uuid = await DiroxReactNativeBlePeripheral.getUUIDFromBytes(bytes)

4. addCharacteristicService

await DiroxReactNativeBlePeripheral.addCharacteristicService(serviceUuid: String, uuid: String, property: int <ENUM>, permission: int<ENUM>)
PROERTY_ENUM:
- INDICATE = 32
- NOTIFY = 16
- READ = 2
- WRITE = 8
PERMISSION_ENUM:
- READ = 1
- WRITE = 16
Example:
let result = await DiroxReactNativeBlePeripheral.addCharacteristicService(uuidService1, '9b1deb4d-9bdd-9bdd-9bdd-2b0d7b3dcb6d', 2, 16)

5. start

 let result = await DiroxReactNativeBlePeripheral.start("BLE NAME") 
 - result = 0 : user disabled bluetooth
 - result = 1 : success

6. sendNotificationToDevices / sendNotificationToDevice

let result = await DiroxReactNativeBlePeripheral.sendNotificationToDevices(serviceUuid: String, charUuid: String, message: number[])
or
let result = await DiroxReactNativeBlePeripheral.sendNotificationToDevice(device: String, serviceUuid: String, charUuid: String, message: number[])

Example:

let result = await DiroxReactNativeBlePeripheral.sendNotificationToDevices(uuidService1, "9b1deb4d-9bdd-9bdd-9bdd-2b0d7b3dcb6d", [207,159,136,23,88,11,74,78,170,181,159,182,222,160,147,66,35])

7. stop

 let result = await DiroxReactNativeBlePeripheral.stop()

8. setName

let result = await DiroxReactNativeBlePeripheral.setName("NewName")

9. sendResponse

let requestId = 123
let result = await DiroxReactNativeBlePeripheral.sendResponse(requestId, "Value", "deviceAddress")

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