react-native-ble-plx – React Native Bluetooth Low Energy (BLE) library

This is React Native Bluetooth Low Energy library using RxBluetoothKit and RxAndroidBle under the hood.

scanAndConnect() {
    this.manager = new BleManager();

    // Wait for PoweredOn state

    this.manager.startDeviceScan(null, null, (error, device) => {
        if (error) {
            return;
        }

        // Check if it is a device you are looking for based on advertisement data
        // or other criteria.
        if (device.name === 'TI BLE Sensor Tag' || 
            device.name === 'SensorTag') {
            
            // Stop scanning as it's not necessary if you are scanning for one device.
            this.manager.stopDeviceScan();

            // Proceed with connection.
            device.connect()
                .then((device) => {
                    return device.discoverAllServicesAndCharacteristics()
                })
                .then((device) => {
                   // Do work on device with services and characteristics
                })
                .catch((error) => {
                    // Handle errors
                });
        }
    });
}

Damnit, now I want to take on a new React Native project where I can use this library 😅

react-native-ble-plx (GitHub) →
react-native-ble-plx Documentation →

Published by Bramus!

Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Join the Conversation

2 Comments

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.