GithubHelp home page GithubHelp logo

jacobrosenthal / react-native-ble Goto Github PK

View Code? Open in Web Editor NEW
168.0 11.0 45.0 247 KB

Central role BLE for react native noble api surface

License: MIT License

Objective-C 35.14% JavaScript 18.75% Java 46.11%

react-native-ble's Introduction

react-native-ble

Central role ble for react native. Technically a shim for the excellent noble

install

npm i --save react-native-ble

For ios also see the react native linking guide, but basically

npm install rnpm -g
rnpm link

For android also see https://facebook.github.io/react-native/docs/native-modules-android.html#register-the-module in the paragraph starting "The package needs to be provided..." for the required edits to getPackages() in MainApplication.java.

use

See the noble api for usage

var noble = ('react-native-ble');

For more advanced usage, like in the eddystone_beacon_scanner, include noble directly or utilize a package that does so:

var noble = ('noble');

And follow the instructions in rn-nodeify to deep shim react-native-ble for noble.

react-native-ble's People

Contributors

blakewilliams avatar bryant1410 avatar gilesvangruisen avatar jacobrosenthal avatar rabbitom avatar rclai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-ble's Issues

Writing a characteristic

import Buffer from 'buffer';

let data = new Buffer(1);
data.writeUInt8(5, 0)
characteristic.write(data ,false, (err) => { console.log(err) }

but I get an error

_buffer2.default is not a constructor

How should I do?

Thanks, I found the solution.

Cannot read property 'getState' of undefined

I'm trying to load react-native-ble within android using this require function.

var noble = require('noble');

I'm experiencing this error. Would you know what would be causing this error

Thanks,

Moses

screen shot 2017-05-08 at 4 10 36 pm

sendDeviceEventWithName:body is deprecated

When building the project in Xcode, I get this deprecation message ~18 times. Everything still works, so not a severe problem yet.

RNBLE: 1.0.8
Xcode: 8.3
Base SDK: IOS 10.3
React-Native: 0.42.3
React: 15.4.2

screen shot 2017-03-31 at 11 29 30 am

Illegal invocation

if i call noble.on('stateChange', console.log); i will get an error

Illegal invocation
Noble.EventEmitter.emit
events.js @77:0

here is full code. could anyone help?

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
    TouchableHighlight,
    DeviceEventEmitter
} from 'react-native';
import Orientation from 'react-native-orientation';

import { Accelerometer } from 'NativeModules';
var noble = require('react-native-ble');


Accelerometer.setAccelerometerUpdateInterval(5);
class arduinoCar extends Component {

    handlePressIn(){
        Accelerometer.startAccelerometerUpdates();
    }

    handlePressOut(){
        Accelerometer.stopAccelerometerUpdates();
    }

    componentWillMount(){
        noble.on('stateChange', console.log);
        //noble.on('discover', console.log);

    }

    componentDidMount(){
        Orientation.lockToLandscape();
        DeviceEventEmitter.addListener('AccelerationData', function (data) {
            console.log('acceleration data ', data.acceleration);
        });
    }

  render() {
    return (
      <View style={styles.container}>
          <TouchableHighlight underlayColor='#A74040'
                                style={styles.button}
                              onPressIn={this.handlePressIn}
                              onPressOut={this.handlePressOut}>
            <Text style={styles.buttonText}>Start</Text>
          </TouchableHighlight>
      </View>
    );
  }
}
AppRegistry.registerComponent('arduinoCar', () => arduinoCar);

noble.on is not a function

So I'm trying to run the advertisement_discovery example on my iphone, but I see the error

noble.on is not a function, noble.on is undefined error. Is there any idea why this error is occurring.

Thanks

noble characteristic write error : 'Invalid parameter not satisfying: data != nil'

Hello,

Is there any working write example ?

I'm trying to use it and I had a first issue : buffer is not defined, so I added the shim.js before calling react-native-ble but I had this error :

[fatal][tid:com.facebook.react.RNBLEQueue] Exception 'Invalid parameter not satisfying: data != nil' was thrown while invoking write on target RNBLE with params (
    "AA542816-1CD6-8FF8-2766-BCBF89A4A634",
    "4B48E81D-BFBD-4334-8CB5-1F941E00AA50",
    "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFF4",
    Samoud,
    1
)

Here is my code :

return new Promise(function(resolve, reject) {
      self._connectDevice(peripheral, id)
      .then((characteristic) => {
        // data = 'Samoud'
        characteristic.write(data, true, function(error) {
          if (error) reject(error);
          resolve(true);
        });
      })
      .catch((error) => reject(error));
    });

Any idea how to fix this please ?

List of characteristics are empty in service

I am trying to connect to my Arduino via BLE using this library. But for some reason the services array are always empty:

Here's my code

    noble.on('stateChange', function(state) {
      if (state === 'poweredOn') {
        //
        // Once the BLE radio has been powered on, it is possible
        // to begin scanning for services. Pass an empty array to
        // scan for all services (uses more time and power).
        //
        console.log('scanning...');
        noble.startScanning(['0000222000001000800000805f9b34fb'], false);
      }
      else {
        noble.stopScanning();
      }
    })

    noble.on('discover', function(peripheral) {
      console.log(peripheral);
      // we found a peripheral, stop scanning
      noble.stopScanning();

      console.log("scanning stopped")


      peripheral.connect(err => {
        peripheral.discoverServices(['0000222000001000800000805f9b34fb'], function(err, services) {
          console.log({error: err, service: services});
        });
      })

    });

And this is the output:
capture

this.RNBLE.getState is undefined

Hi, I'm making an extremely simple react-native scene using react-native-ble:

import React from 'react';
const noble = require('react-native-ble');
import {Text, View} from 'react-native';

export default class NodeConfigScene extends React.Component {
  constructor(props) {
    super(props)
  }

  componentWillMount() {
    noble.on('stateChange', this._onStateChange);
    noble.on('discover', this._onDiscover);
  }

  _onStateChange (state) {
    if (state === 'poweredOn') {
      noble.startScanning();
    } else {
      noble.stopScanning();
    }
  };

  _onDiscover (item) {
    console.log(item);
  };
  
  render() {
    return(
      <View><Text>Scanning...</Text></View>
    )
  }
}

This code is extremely similar to the advertisement discovery example. However, when I launch my app, I get the following error redscreen: undefined is not an object (evaluating 'this.RNBLE.getState')

Since the example app that does almost exactly the same thing works, I'm suspecting this has something to do with my using react-native-router-flux or redux (or something else) in the same app.

Any ideas why I'm getting this error?

Cannot subscribe to multiple characteristics

Hi. I'm trying to talk to an Arduino with Nordic BLE chip, but I cannot subscribe to multiple characteristics on Android 7.0. The code below successfully subscribed to the Battery characteristic, but not the Uuart (and no error message is displayed). If I reverse the order of subscription, putting UART before battery, then the UART gets successfully subscribed, but not the battery. The console line "Subscribing #2" is displayed, so I think that it's probably getting to the second subscribe() function, but that the function is not being executed.

subscribeToCharacteristics() {
  this.blueFruitUuartRxChar.on('read', function(data, isNotification) {
    let message = data.toString();
    tokens = message.split(',');
    if (tokens.length == 3) {
      temp = parseFloat(tokens[0]);
      pot = parseFloat(tokens[1]);
      press = parseFloat(tokens[2]);
      this.setState({
        temperature: temp,
        potValue: pot,
        pressure: press,
      });
    }
  }.bind(this));

  this.blueFruitBatteryChar.on('read', function(data, isNotification) {
    let level = data.readUInt8(0);
    this.setState({batteryLevel: level});
  }.bind(this));

  this.blueFruitBatteryChar.subscribe(function(error) {
    if (error) {
      this.setState({log: this.state.log + '\r\nError subscribing to Battery'});
    }
    else {
      console.log('Subscribed to Battery');
    }
  }.bind(this));

  console.log('Subscribing #2');
  this.blueFruitUuartRxChar.subscribe(function(error) {
    if (error) {
      this.setState({log: this.state.log + '\r\nError subscribing to UART'});
    }
    else {
      console.log('Subscribed to UART');
    }}.bind(this));
};

Can't get characteristics list of a service

I want to get all characteristics list of a service. Every time I get empty characteristics array. I have used following ways to get characteristics list:

  • `service.discoverCharacteristics(null, function(error, characteristics) {

          });`
    
  • service.once('characteristicsDiscover', (characteristics)=>{ }); service.discoverCharacteristics();

Both of these approaches do not work.

Not registering iBeacon advertisment

Hi, I'm trying to use react-native-ble on an Iphone to detect IBeacons. When I do this using plain noble on my computer I get advertisements that look like this:

{
  localName: undefined,
  txPowerLevel: undefined,
  manufacturerData: <Buffer 4c 00 02 15 4e dc e9 15 9f bb 61 8b 47 f6 f2 03 bb dd 08 9a 3e fc ce 24 b8>,
  serviceData: [],
  serviceUuids: []
}

This is what I would expect. The first hex in the buffer corresponds to Apple's company identifier, and I verified that the uuid embedded in the buffer is the same as the one I'm advertising via IBeacon.

However, when I do this in a react native app (i.e. scanning with react-native-ble) and simply logging the results, the advertisement key is empty. However, it seems to work for non-IBeacon advertisments. E.g.

{ serviceData: 
   [ { uuid: 'fe9a',
       data: 
        { '0': 0, '1': 59, '2': 161, '3': 252, '4': 29, '5': 204, '6': 106, '7': 38,
          '8': 158, '9': 101, '10': 77, '11': 211, '12': 255, '13': 23, '14': 229,
          '15': 134, '16': 11, '17': 145, '18': 68, '19': 64 } } ],
  serviceUuids: [ 'fe9a' ]
}

This is the advertisement for some other bluetooth thing in my house. (Not sure exactly what it is).

I have tried detecting the IBeacons both in my own app and in the 'advertisement-discovery' example app, and the same problem happens: react-native-ble discovers things, but IBeacons advertisements are missing. What is going wrong here? Why can't react-native-ble detect IBeacon advertisements?

Is it possible to use it with the simulator?

Hi, sorry for the beginner question, but I am struggling to find examples.
Do you use any simulator to develop with react-native? I am getting "unsupported" state while using iOS simulator within OSX.

Hope it is my bad!

Readme unclear

What does this mean:

Only supports scanning advertisements currently

Notify not working on Android

Hello, the notify function doesn't seem to be included as a binding in bindings.android.js. Any reason for this? This API works fine with me in discovering services, characteristics and reading them, but trying to use the notify function gives me an error "undefined is not a function (evaluating 'this._bindings.notify(peripheralUuid,serviceUuid,characteristicUuid,notify)')". Using console.log(noble) right after importing noble gives me the following:

{ state: 'unknown',
I/ReactNativeJS( 7470): address: 'unknown',
I/ReactNativeJS( 7470): _bindings:
I/ReactNativeJS( 7470): { init: [Function],
I/ReactNativeJS( 7470): connect: [Function],
I/ReactNativeJS( 7470): disconnect: [Function],
I/ReactNativeJS( 7470): startScanning: [Function],
I/ReactNativeJS( 7470): stopScanning: [Function],
I/ReactNativeJS( 7470): discoverServices: [Function],
I/ReactNativeJS( 7470): discoverIncludedServices: [Function],
I/ReactNativeJS( 7470): discoverCharacteristics: [Function],
I/ReactNativeJS( 7470): discoverDescriptors: [Function],
I/ReactNativeJS( 7470): read: [Function],
I/ReactNativeJS( 7470): write: [Function],
I/ReactNativeJS( 7470): _events:
I/ReactNativeJS( 7470): { stateChange: [Function],
I/ReactNativeJS( 7470): addressChange: [Function],
I/ReactNativeJS( 7470): scanStart: [Function],
I/ReactNativeJS( 7470): scanStop: [Function],
I/ReactNativeJS( 7470): discover: [Function],
I/ReactNativeJS( 7470): connect: [Function],
I/ReactNativeJS( 7470): disconnect: [Function],
I/ReactNativeJS( 7470): rssiUpdate: [Function],
I/ReactNativeJS( 7470): servicesDiscover: [Function],
I/ReactNativeJS( 7470): includedServicesDiscover: [Function],
I/ReactNativeJS( 7470): characteristicsDiscover: [Function],
I/ReactNativeJS( 7470): read: [Function],
I/ReactNativeJS( 7470): write: [Function],
I/ReactNativeJS( 7470): broadcast: [Function],
I/ReactNativeJS( 7470): notify: [Function],
I/ReactNativeJS( 7470): descriptorsDiscover: [Function],
I/ReactNativeJS( 7470): valueRead: [Function],
I/ReactNativeJS( 7470): valueWrite: [Function],
I/ReactNativeJS( 7470): handleRead: [Function],
I/ReactNativeJS( 7470): handleWrite: [Function],
I/ReactNativeJS( 7470): handleNotify: [Function] } },
I/ReactNativeJS( 7470): _peripherals: {},
I/ReactNativeJS( 7470): _services: {},
I/ReactNativeJS( 7470): _characteristics: {},
I/ReactNativeJS( 7470): _descriptors: {},
I/ReactNativeJS( 7470): _discoveredPeripheralUUids: [],
I/ReactNativeJS( 7470): _events: { warning: [Function] } }

The piece of code i'm trying to test this on is a slightly modified version of one of nobles example codes:

if (peripheral.advertisement.serviceUuids.includes("0000180900001000800000805f9b34fb")) {
peripheral.connect(function(error) {
peripheral.discoverServices(['0000180900001000800000805f9b34fb'], function(error, services) {
var serviceIndex = 0;
while (serviceIndex < services.length) {
var batteryService = services[serviceIndex];
batteryService.discoverCharacteristics(['00002a1c00001000800000805f9b34fb'], function(error, characteristics) {
var characteristicIndex = 0;
while (characteristicIndex < characteristics.length) {
var batteryLevelCharacteristic = characteristics[characteristicIndex];
batteryLevelCharacteristic.read(function(error, data) {
if (data) {
var string = data.toString('ascii');
var characteristicOut = data.toString('hex');
}
});
batteryLevelCharacteristic.on('data', function(data, isNotification) {
console.log(data);
});
batteryLevelCharacteristic.notify(true, function(error) {
console.log('battery level notification on');
});
characteristicIndex++;
}
});
serviceIndex++;
}
});
});
}

Am I missing something or is the notify function purposely not included?

Turn on bluetooth to allow "App Name" to connect to accessories.

I am using this excellent library to connect with a heart rate monitor for workout recording. Unfortunately, when bluetooth is disabled the user gets this alert on every launch. I would rather handle the alert internally...

I believe this is happening because the module initializes on app launch. Is there any way to initialize only when bluetooth is turned on, and if it is off, add a listener to initialize when it is turned on?

I did a little research, and this SO question seems to be related. Unfortunately I don't really know what I'm doing in objective-c, otherwise I would submit a PR myself.

Let me know if you have any thoughts, or if I could accomplish this with js somehow!

Thanks : )

React Native Packager - Module replacement?

Im not sure how/if module replacement is supposed to work in react packager. Or maybe we need to look into https://github.com/mjohnston/react-native-webpack-server ?

For now Im (sadly) editing files manually

//var noble = require('noble');
var noble = require('react-native-ble');

But its a deep rabbit hole. The eddystone-url-encoding module does a json require without specifying the extension which the react native packager doesnt seem to support

// var prefixes = require('./prefixes');
var prefixes = require('./prefixes.json');
// var suffixes = require('./suffixes');
var suffixes = require('./suffixes.json');

Build Fail with RN v .0.40.0 'sendDeviceEventWithName:body:' is deprecated

I created a new project using RN v 0.40.0. Following, installed and linked the RN-blu library I get the errors below that sendDeviceEventWithName:body has been marked as deprecated.

Moses

/Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:62:32: warning: 'sendDeviceEventWithName:body:' is deprecated: Subclass RCTEventEmitter instead [-Wdeprecated-declarations]
[self.bridge.eventDispatcher sendDeviceEventWithName:@"ble.discover" body:@{
^
In file included from /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:2:
../../node_modules/react-native/React/Base/RCTEventDispatcher.h:83:1: note: 'sendDeviceEventWithName:body:' has been explicitly marked deprecated here

  • (void)sendDeviceEventWithName:(NSString *)name body:(id)body
    ^
    /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:100:32: warning: 'sendDeviceEventWithName:body:' is deprecated: Subclass RCTEventEmitter instead [-Wdeprecated-declarations]
    [self.bridge.eventDispat
    cher sendDeviceEventWithName:@"ble.connect" body:@{
    ^
    In file included from /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:2:
    ../../node_modules/react-native/React/Base/RCTEventDispatcher.h:83:1: note: 'sendDeviceEventWithName:body:' has been explicitly marked deprecated here
  • (void)sendDeviceEventWithName:(NSString *)name body:(id)body
    ^
    /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:111:32: warning: 'sendDeviceEventWithName:body:' is deprecated: Subclass RCTEventEmitter instead [-Wdeprecated-declarations]
    [self.bridge.eventDispatcher sendDeviceEventWithName:@"ble.disconnect" body:eventData];
    ^
    In file included from /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:2:
    ../../node_modules/react-native/React/Base/RCTEventDispatcher.h:83:1: note: 'sendDeviceEventWithName:body:' has been explicitly marked deprecated here
  • (void)sendDeviceEventWithName:(NSString *)name body:(id)body
    ^
    /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:116:32: warning: 'sendDeviceEventWithName:body:' is deprecated: Subclass RCTEventEmitter instead [-Wdeprecated-declarations]
    [self.bridge.eventDispatcher sendDeviceEventWithName:@"ble.connect" body:@{
    ^
    In file included from /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:2:
    ../../node_modules/react-native/React/Base/RCTEventDispatcher.h:83:1: note: 'sendDeviceEventWithName:body:' has been explicitly marked deprecated here
  • (void)sendDeviceEventWithName:(NSString *)name body:(id)body
    ^
    /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:150:34: warning: 'sendDeviceEventWithName:body:' is deprecated: Subclass RCTEventEmitter instead [-Wdeprecated-declarations]
    [self.bridge.eventDispatcher sendDeviceEventWithName:@"ble.rssiUpdate" body:@{
    ^
    In file included from /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:2:
    ../../node_modules/react-native/React/Base/RCTEventDispatcher.h:83:1: note: 'sendDeviceEventWithName:body:' has been explicitly marked deprecated here
  • (void)sendDeviceEventWithName:(NSString *)name body:(id)body
    ^
    /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:193:34: warning: 'sendDeviceEventWithName:body:' is deprecated: Subclass RCTEventEmitter instead [-Wdeprecated-declarations]
    [self.bridge.eventDispatcher sendDeviceEventWithName:@"ble.servicesDiscover" body:@{
    ^
    In file included from /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:2:
    ../../node_modules/react-native/React/Base/RCTEventDispatcher.h:83:1: note: 'sendDeviceEventWithName:body:' has been explicitly marked deprecated here
  • (void)sendDeviceEventWithName:(NSString *)name body:(id)body
    ^
    /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:207:34: warning: 'sendDeviceEventWithName:body:' is deprecated: Subclass RCTEventEmitter instead [-Wdeprecated-declarations]
    [self.bridge.eventDispatcher sendDeviceEventWithName:@"ble.includedServicesDiscover" body:@{
    ^
    In file included from /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:2:
    ../../node_modules/react-native/React/Base/RCTEventDispatcher.h:83:1: note: 'sendDeviceEventWithName:body:' has been explicitly marked deprecated here
  • (void)sendDeviceEventWithName:(NSString *)name body:(id)body
    ^
    /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:299:34: warning: 'sendDeviceEventWithName:body:' is deprecated: Subclass RCTEventEmitter instead [-Wdeprecated-declarations]
    [self.bridge.eventDispatcher sendDeviceEventWithName:@"ble.characteristicsDiscover" body:@{
    ^
    In file included from /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:2:
    ../../node_modules/react-native/React/Base/RCTEventDispatcher.h:83:1: note: 'sendDeviceEventWithName:body:' has been explicitly marked deprecated here
  • (void)sendDeviceEventWithName:(NSString *)name body:(id)body
    ^
    /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:314:34: warning: 'sendDeviceEventWithName:body:' is deprecated: Subclass RCTEventEmitter instead [-Wdeprecated-declarations]
    [self.bridge.eventDispatcher sendDeviceEventWithName:@"ble.descriptorsDiscover" body:@{
    ^
    In file included from /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:2:
    ../../node_modules/react-native/React/Base/RCTEventDispatcher.h:83:1: note: 'sendDeviceEventWithName:body:' has been explicitly marked deprecated here
  • (void)sendDeviceEventWithName:(NSString *)name body:(id)body
    ^
    /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:471:34: warning: 'sendDeviceEventWithName:body:' is deprecated: Subclass RCTEventEmitter instead [-Wdeprecated-declarations]
    [self.bridge.eventDispatcher sendDeviceEventWithName:@"ble.notify" body:@{
    ^
    In file included from /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:2:
    ../../node_modules/react-native/React/Base/RCTEventDispatcher.h:83:1: note: 'sendDeviceEventWithName:body:' has been explicitly marked deprecated here
  • (void)sendDeviceEventWithName:(NSString *)name body:(id)body
    ^
    /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:483:34: warning: 'sendDeviceEventWithName:body:' is deprecated: Subclass RCTEventEmitter instead [-Wdeprecated-declarations]
    [self.bridge.eventDispatcher sendDeviceEventWithName:@"ble.data" body:@{
    ^
    In file included from /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:2:
    ../../node_modules/react-native/React/Base/RCTEventDispatcher.h:83:1: note: 'sendDeviceEventWithName:body:' has been explicitly marked deprecated here
  • (void)sendDeviceEventWithName:(NSString *)name body:(id)body
    ^
    /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:496:34: warning: 'sendDeviceEventWithName:body:' is deprecated: Subclass RCTEventEmitter instead [-Wdeprecated-declarations]
    [self.bridge.eventDispatcher sendDeviceEventWithName:@"ble.valueUpdate" body:@{
    ^
    In file included from /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:2:
    ../../node_modules/react-native/React/Base/RCTEventDispatcher.h:83:1: note: 'sendDeviceEventWithName:body:' has been explicitly marked deprecated here
  • (void)sendDeviceEventWithName:(NSString *)name body:(id)body
    ^
    /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:518:34: warning: 'sendDeviceEventWithName:body:' is deprecated: Subclass RCTEventEmitter instead [-Wdeprecated-declarations]
    [self.bridge.eventDispatcher sendDeviceEventWithName:@"ble.valueWrite" body:@{
    ^
    In file included from /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:2:
    ../../node_modules/react-native/React/Base/RCTEventDispatcher.h:83:1: note: 'sendDeviceEventWithName:body:' has been explicitly marked deprecated here
  • (void)sendDeviceEventWithName:(NSString *)name body:(id)body
    ^
    /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:531:34: warning: 'sendDeviceEventWithName:body:' is deprecated: Subclass RCTEventEmitter instead [-Wdeprecated-declarations]
    [self.bridge.eventDispatcher sendDeviceEventWithName:@"ble.write" body:@{
    ^
    In file included from /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:2:
    ../../node_modules/react-native/React/Base/RCTEventDispatcher.h:83:1: note: 'sendDeviceEventWithName:body:' has been explicitly marked deprecated here
  • (void)sendDeviceEventWithName:(NSString *)name body:(id)body
    ^
    /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:591:32: warning: 'sendDeviceEventWithName:body:' is deprecated: Subclass RCTEventEmitter instead [-Wdeprecated-declarations]
    [self.bridge.eventDispatcher sendDeviceEventWithName:@"ble.stateChange" body:[self NSStringForCBCentralManagerState:[central state]]];
    ^
    In file included from /Users/rowvigor/git/c2tes
    t/node_modules/react-native-ble/RNBLE.m:2:
    ../../node_modules/react-native/React/Base/RCTEventDispatcher.h:83:1: note: 'sendDeviceEventWithName:body:' has been explicitly marked deprecated here
  • (void)sendDeviceEventWithName:(NSString *)name body:(id)body
    ^
    /Users/rowvigor/git/c2test/node_modules/react-native-ble/RNBLE.m:591:119: warning: implicit conversion from enumeration type 'CBManagerState' (aka 'enum CBManagerState') to different enumeration type 'CBCentralManagerState' (aka 'enum CBCentralManagerState') [-Wenum-conversion]
    [self.bridge.eventDispatcher sendDeviceEventWithName:@"ble.stateChange" body:[self NSStringForCBCentralManagerState:[central state]]];
    ~ ^~~~~~~~~~~~~~~

Can't read descriptor value

When I have discovered descriptors, I try to do readValue on the descriptor but it keeps giving me this error (on android). (Even though I can see the readValue function in proto inside the object)

console.log(descriptors[descriptorIndex]);
descriptors[descriptorIndex].readValue(function(error, data){
   console.log("descriptor readValue:"+data);
});

capture

Am I doing something wrong or is this a bug?

"Data must be a buffer" error from noble.js

Run in to a error "data must be a buffer" after merging the latest changes from master branch to my project. The error happens when writing to a characteristic in iOS e.g.

someCharacteristic.write(new Buffer.from(data, "hex");
--> causes an error "data must be a buffer"

This is the same problem as described here:
noble/noble#388 (comment)

And as described in the above this was worked around by adding a characteristic prototype function in index.js

The prototypes were however removed as part of the recent (July) commit and the problem appeared again.

After adding the characteristic prototype back I got the project working again.

Is the characteristic prototype still needed or should this be handled differently from now on?

Tracking connect, services, characteristics, reads and writes

Hi,

I'm currently considering a react native ble plugin, may even port the existing ble central plugin from cordova (we're moving from cordova -> react-native), as that's what we're currently using. Then I've found this library, it would be cool if we could port the cordova implementation and apply it to the same noble-style interface and have it working with react-native.

So I'm just interested why you stopped at scanning?

noble.state is `unsupported` on evey other launch (iOS)

I find that on every other launch (if i use the react-native debug menu Reload or by killing the app and launching it again) on one load the state will be poweredOn and I'll get state updates if i turn on/off iOS bluetooth.

Then the next launch, state will be unsupported and I will get no state updates events.

It seems to flip flop, but every so often it will behave the same way on two subsequent launches.

Am I not shutting down noble properly? Thoughts?

Security?

Hi there,

I haven't had the opportunity to give this a try yet, but will do so in the next few days, it looks great!

I'm building an application where data security between the peripheral and central devices will be quite important. Has there been any consideration around which SMPs should be implemented and how they could be leveraged via the API? I believe Noble has the concept of a "Secure Characteristic" which relies on the "Just Works" SMP.

I'd like to implement OOB pairing, or at least passcode pairing for my purposes. Happy to have a discussion around contributing a PR, though my focus will be on Android at this stage.

Thanks,

Strainy

[discussion] Adding automatic Noble support via bindings

Hey Jacob!!

Thanks so much for putting in the work to get Noble running within React Native. I'm super impressed by your work here implementing the bindings in both Obj-C and Java, as well as your React Native PR adding support for deep shimming.

I was thinking about the issues around deep shimming and poking the Noble lib itself, and I think we might potentially be able to get around the need for deep shimming and also be able to import noble, which would rely on this when running in RN, rather than importing this library directly.

I think we can potentially solve this by adding direct binding support and including react-native-ble for those bindings. This could potentially get around the deep shimming issue if react-native-ble is included in noble's dependencies. However, that's obviously that's not ideal for every other project using noble, so I think we'd instead want to include react-native-ble under the "react-native" field in noble's package.json.

I'm going to take a stab at this locally and see what I can get to work. I'll post an update here with what I find.

Also: looks like that React Native PR #9899 was closed. If you're too busy to finish that up, I'm happy to take it over to make those changes and credit you.

Thanks again for putting this library together!!

state / stateChange behavior [Android]

I am a bit confused as to how state / stateChange work...I initially assumed that a stateChange event would be automatically emitted when the user enables / disables bluetooth, but this doesn't seem to be the case. I then thought I should check whether bluetooth is on or off (whenever I need it), and change the state + emit event myself (" noble.state = 'poweredOn; noble.emit('stateChange', 'poweredOn' "), but even though this changes the noble.state to whatever I want it to, when I try and scan for devices, the scan actually starts but doesn't actually find anything (even though there are devices to be found).

In short: if I start the app with bluetooth off, I don't seem to be able to find devices even though I subsequently enable bluetooth, change noble state to 'poweredOn', and emit the appropriate 'stateChange' event.

I would greatly appreciate anyone shedding some light on this, and whether this behavior is normal (but I'm doing it wrong), or is it a bug?

Different UUID format when running in my RN app and directly from noble/example/advertisement.js

In my App, I'm trying to connect to an arduino using react-native-ble.

I've followed this step

When I run it in noble/example/advertisement.js, it returns the following:
capture

But when I try to search it in my App, I get the following:

capture

This is a big issue because I cant connect to my arduino.

My services UUID should be 4 digits long for example:

Should be

1800
1801
2220

Not:

0000180000001....
0000180100001....
0000222100001....

Why is this happening?

Update

I've tested and its confirmed that it's only this library that prints the following:
capture

What change is required in order to provide the correct UUID?

Upgrade for compatibility with React-Native 0.40.0

Hi, when I use react-native-ble in the latest versions of react-native I get the following errors when building with Xcode:

screen shot 2017-01-17 at 12 15 26 am

Expected:
Project compiles and runs without errors.

Steps to reproduce:

  1. Run:
react-native init test
cd test
npm install react-native-ble --save
rnpm link
  1. Open project and run in Xcode.

Thank you!

Eddystone protocol

Hi everyone.

Anyone can help me to implement the Eddystone Scanner?

Im trying with nodeify, but no success yet.

A single step by step may be helpful... I cant run the app on the example folder.

Thanks!

Error with running App with react-native-ble on Android in debug mode

Hi,

I'm attempting to run App on react-native-ble on my Adroid, but I recieve this error. How would I fix it?

AndroidManifest.xml:9:5-11:41 Error:
uses-sdk:minSdkVersion 16 cannot be smaller than version 21 declared in library

Suggestion: use tools:overrideLibrary="com.geniem.rnble" to force usage

How to advertise?

Hi, is that possible to advertise? (that other device can discover my device)
if not can you please explain me why? do you think there are other libraries which able to do that or we can't do it right now with react native?

Thank you

Unable to resolve module 'url'

I'm loading noble on the app.

var noble = require('noble');

I get this error, see attached screen shot. What do you suggest I do to fix it.

screen shot 2017-03-03 at 9 19 30 am

RCTConvert.h file not found when building for release

I am getting errors while building for release with the BLE library in Xcode. "RCTCONVERT+CBUUID.h cannot find the RCTConvert.h file, though it is installed (via npm install) in the react-native folder within node_modules. I have been able to resolve the error by changing the import of the file to the absolute path, then I get the same error for the rest of the imports.

Anyone else had this same issue?

no initial stateChange

The existing bindings seem to just happen to catch the initial statechange, but with all the react setup that event is lost before we're all set up to catch it.

Currently I'm not waiting for a stateChange event, Im just scanning as soon as the app opens.

Evaluate react-native-ble-plx native code

The point of this library is to bring noble style bindings to react-native as I find noble to be a stable, enjoyable api for bluetooth thats incredibly multiplatform (mac/linux/osx as well as web and mobile web)

Our strong suit was never our native implementations. We dont have unit tests and many of us have touched that code at this point so we dont have a strong authorial voice.

Id love any feedback on react-native-ble-plx. (as well as send anyone there who doesnt care about noble, theyre probably going to serve you better)

Perhaps we can leverage their native work instead of our own? or learn from it at the very least.

ios simulator app crashing with react-native-ble library installed

I created a RN .4 project with installing the react-native-ble library installed. I made all the updates to the included library. The entire app builds successfully. However, everytime I launch the IOS simulator with the react-native-blu library linked to the simulator it crashes. I see no error messages. Any insight the reason this maybe be occurring.

Moses

Background Restoration

When we last left our heroes, the big missing functionality was being awoken from sleep and restoring bluetooth. From my react native issue: facebook/react-native#1660

Right now when an app is launched, the launchoptions are given to a native module via the setBridge function. This is handy for push notifications as you can know what notification launched you, etc.

That paradigm doesnt work for Corelocation and Corebluetooth restoration though. These trigger a didFinishLaunchingWithOptions in order to tell the app that a location or device it was told to track has resurfaced. The rest of the app is never launched though, so setbridge never happens. Its common to do a push notification right there or restart your bluetooth stack to do some action. So I think we need a way to register functions to be called upon those launchoptions keys.

I saw this while skimming code around this issue, could we do this:
https://github.com/facebook/react-native/blob/d5209a082976d272e6e897c41fb6f98feda84081/Examples/UIExplorer/UIExplorer/AppDelegate.m#L29

Crash on iOS

react-native init TestApp
cd TestApp
npm install --save react-native-ble
rnpm link
react-native run-ios

The project builds fine, but crashes upon startap in RNBLE module.
Even without js actually using it.
Android works fine!

Using Noble on iOS trough react-native-ble

I'm having some problems running react-native-ble and with the deep shim react-native-ble for noble.

My goal is to use the node-eddystone-beacon-scanner.

I tried using rn-nodeify as told but whenever I try to get an instance of noble directly I get unable to resolve bluetooth-hci-socket from noble/lib/hci-socket.

Has any one used this with iOS? Is it possible?

Also, the same code would work on Android?

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.