0

I've been using an Arduino Nano 33 BLE to communicate with my PC over the BlueFruit LE Friend's UART characteristic. Using the default ArduinoBLE library, I'm able to connect to the BlueFruit from the Nano 33 as a central device, and write to the BlueFruit and have it show up in a serial terminal. I can get the Nano 33 to read from the Bluefruit as well, by sending a Characteristic.read() request and a subsequent Charcterisitc.readValue() command. Subscribing to the rx characterisitic on the Nano 33 does NOT work, however, even though the Bluefruit's info page says that the rx characterisitc (address 0x0003) is capable of Notify. I need to be able to subscribe, so that I can use the characteristic.valueUpdated() function to know when new data is available. Here is the relevant code:

if (peripheral.connect()) {
Serial.println("Connected");
} else {
Serial.println("Failed to connect!");
return;
}

// discover peripheral attributes
Serial.println("Discovering attributes ...");
displayNum('A');
if (peripheral.discoverAttributes()) {
  Serial.println("Attributes discovered");
  displayNum(-1);
} else {
  Serial.println("Attribute discovery failed!");
  peripheral.disconnect();
  displayError('A');
  return;
}

// retrieve the TX characteristic
BLECharacteristic txCharacteristic = peripheral.characteristic("6e400002-b5a3-f393-e0a9-e50e24dcca9e");
BLECharacteristic rxCharacteristic = peripheral.characteristic("6e400003-b5a3-f393-e0a9-e50e24dcca9e");

// make sure BlueFruit UART characteristics have been loaded properly are of
// proper format
if (!txCharacteristic) {
  Serial.println("Peripheral does not have TX characteristic!");
  peripheral.disconnect();
  return;
} else if (!txCharacteristic.canWrite()) {
  Serial.println("Peripheral does not have a writable TX characteristic!");
  peripheral.disconnect();
  return;
}
if (!rxCharacteristic) {
  Serial.println("Peripheral does not have RX characteristic!");
  peripheral.disconnect();
  return;
} else if (!rxCharacteristic.canSubscribe()) {
  Serial.println("rxCharacteristic is not subscribable!");
  peripheral.disconnect();
  return;
} else if (!rxCharacteristic.subscribe()) {
  Serial.println("rxCharacteristic subscription failed!");
  peripheral.disconnect();
  return;
}

What's strange is that Characteristic.canSubscribe() method returns true, and it is only when I actually try to subscribe that my error message is triggered. This code is also basically taken directly from the ArduinoBLE SensorTag example, so I'm not sure if this is an issue with the Arduino library or the Bluefruit, so any input would be appreciated.

  • As an update, I'm able to get notifications through the BlueFruit Connect app, which makes me think that the issue has something more to do with the Arduino library. – willtmakinen May 1 '20 at 0:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.