Skip to content

Cannot subscribe to multiple characteristics #49

@vabalasu

Description

@vabalasu

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));
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions