Description
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 Nano33 as a central device, and write to the BlueFruit and have it show up in a serial terminal. I can get the Nano33 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 Nano33 is an issue, however, even though the Bluefruit's info page says that the rx characterisitc (address 0x0003) is capable of Notify. At first, Charcteristic.subscribe() would always return false, until I followed @gdsport's advice here and modified BLERemoteDescriptor.cpp. Now, although subscribe() returns true, Charcteristic.valueUpdated() always returns false, even when opening up a serial port to the BlueFruit and sending data with the UART service. This is the relevant Arduino code:
BLECharacteristic rxCharacteristic = peripheral.characteristic("6e400003-b5a3-f393-e0a9-e50e24dcca9e");
// make sure BlueFruit UART characteristics have been loaded properly are of
// proper format
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;
}
Serial.println("subscribed");
while (peripheral.connected()) {
if (rxCharacteristic.valueUpdated()) {
Serial.println("value updated");
}
}
For reference, this is the modified code from BLERemoteDescriptor.cpp:
int BLERemoteDescriptor::writeValue(const uint8_t value[], int length)
{
if (!ATT.connected(_connectionHandle)) {
return false;
}
uint16_t maxLength = ATT.mtu(_connectionHandle) - 3;
if (length > (int)maxLength) {
// cap to MTU max length
length = maxLength;
}
_value = (uint8_t*)realloc(_value, length);
if (_value == NULL) {
// realloc failed
return 0;
}
#if 0
uint8_t resp[4];
int respLength = ATT.writeReq(_connectionHandle, _handle, value, length, resp);
if (!respLength) {
return 0;
}
if (resp[0] == 0x01) {
// error
return 0;
}
#else
ATT.writeCmd(_connectionHandle, _handle, value, length);
#endif
memcpy(_value, value, length);
_valueLength = length;
return 1;
}
Any thoughts on what might be causing this?
Arduino IDE version 1.8.12 and ArduinoBLE version 1.1.2