Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot subscribe to multiple characteristics #49

Open
vabalasu opened this issue May 3, 2017 · 3 comments
Open

Cannot subscribe to multiple characteristics #49

vabalasu opened this issue May 3, 2017 · 3 comments

Comments

@vabalasu
Copy link

vabalasu commented May 3, 2017

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));
};
@surajit-bitcanny
Copy link

Have you found any solution for this?

@vabalasu
Copy link
Author

No, I never found a solution.

@surajitsarkar19
Copy link

Immediate characteristics subscription will not work. Try to put a delay between two subscriptions. Then it will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants