A Library for easy implementation of Serial Bluetooth Low Energy on React Native. ⚛
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
android updated core library. Dec 19, 2017
ios First commit May 25, 2017
.babelrc First commit May 25, 2017
.buckconfig First commit May 25, 2017
.flowconfig First commit May 25, 2017
.gitattributes First commit May 25, 2017
.gitignore First commit May 25, 2017
.gitmodules Linked CoreModule as Gradle dependency May 30, 2017
.watchmanconfig First commit May 25, 2017
LICENSE Create LICENSE May 30, 2017
README.md Update README.md Jul 31, 2017
app.json First commit May 25, 2017
index.js Linked CoreModule as Gradle dependency May 30, 2017
jsconfig.json First commit May 25, 2017
package.json

README.md

Easy Bluetooth Low Energy

Licence MIT npm version npm downloads

A Library for easy implementation of Serial Bluetooth Low Energy on React Native. 💙

Looking for Bluetooth Classic? Look here.

Requirements

  • React Native >= 0.40.0
  • Android 4.3 (API 18)
  • iOS soon...

Use

Configuration

import EasyBluetooth from 'easy-bluetooth-le';

...

    var config = {
      "uuidService": "e7810a71-73ae-499d-8c15-faa9aef0c3f2",
      "uuidCharacteristic": "bef8d6c9-9c21-4c9e-b632-bd58c1009f9f",
      "deviceName": "Bluetooth Example Project",
      "bufferSize": 1024,
      "characterDelimiter": "\n"
    }

    EasyBluetooth.init(config)
      .then(function (config) {
        console.log("config done!");
      })
      .catch(function (ex) {
        console.warn(ex);
      });

Scanning

    EasyBluetooth.startScan()
      .then(function (devices) {
        console.log("all devices found:");
        console.log(devices);
      })
      .catch(function (ex) {
        console.warn(ex);
      });

Connecting

    EasyBluetooth.connect(device)
      .then(() => {
        console.log("Connected!");
      })
      .catch((ex) => {
        console.warn(ex);
      })

Writing

    EasyBluetooth.writeln("Works in React Native!")
      .then(() => {
        console.log("Writing...")
      })
      .catch((ex) => {
        console.warn(ex);
      })

Events

componentWillMount() {
    this.onDeviceFoundEvent = EasyBluetooth.addOnDeviceFoundListener(this.onDeviceFound.bind(this));
    this.onStatusChangeEvent = EasyBluetooth.addOnStatusChangeListener(this.onStatusChange.bind(this));
    this.onDataReadEvent = EasyBluetooth.addOnDataReadListener(this.onDataRead.bind(this));
    this.onDeviceNameEvent = EasyBluetooth.addOnDeviceNameListener(this.onDeviceName.bind(this));
}
...
  onDeviceFound(device) {
    console.log("onDeviceFound");
    console.log(device);
  }

  onStatusChange(status) {
    console.log("onStatusChange");
    console.log(status);
  }

  onDataRead(data) {
    console.log("onDataRead");
    console.log(data);
  }
  
  onDeviceName(name) {
    console.log("onDeviceName");
    console.log(name);
  }
...
componentWillUnmount() {
    this.onDeviceFoundEvent.remove();
    this.onStatusChangeEvent.remove();
    this.onDataReadEvent.remove();
    this.onDeviceNameEvent.remove();
}

Install

  1. Run in console:

    npm i -S easy-bluetooth-le
  2. Link:

    react-native link easy-bluetooth-le
  3. Add jitpack repository in android/build.gradle:

    allprojects {
     repositories {
         ...
         maven { url "https://jitpack.io" }
     }
    }
    

Known issues

Contribute

New features, bug fixes and improvements are welcome! For questions and suggestions use the issues.

Become a Patron! Donate

Licence

The MIT License (MIT)

Copyright (c) 2017 Douglas Nassif Roma Junior

See the full licence file.