arduino / arduino/ArduinoCore-arc32
Jira 913 BLESubscribed, BLEUnsubscribed Event Handlers are not called
- Dominant language
- C
- Stars
- 330
- Forks
- 281
- PR merge metrics
- No merged PRs in 30d
Description
For example, in following scenario (Nordic UART Service implementation):
```cpp
#include
BLEService NUS ("713D0000-503E-4C75-BA94-3148F18D941E");
BLECharacteristic rxChar ("713D0003-503E-4C75-BA94-3148F18D941E", BLEWrite | BLEWriteWithoutResponse, BLE_MAX_ATTR_DATA_LEN);
BLECharacteristic txChar ("713D0002-503E-4C75-BA94-3148F18D941E", BLERead | BLENotify, BLE_MAX_ATTR_DATA_LEN);
void setup() {
Serial.begin(9600);
// begin initialization
BLE.begin();
// set the local name peripheral advertises
BLE.setLocalName("NUS test");
BLE.setAdvertisedService(NUS);
// add the characteristic to the service
NUS.addCharacteristic(rxChar);
NUS.addCharacteristic(txChar);
// add service
BLE.addService(NUS);
// assign event handlers for connected, disconnected to peripheral
BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler);
BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);
// assign event handlers for characteristics
rxChar.setEventHandler(BLEWritten, rxCharWritten);
txChar.setEventHandler(BLESubscribed, txCharSubscribed);
txChar.setEventHandler(BLEUnsubscribed, txCharUnsubscribed);
// set an initial value for characteristics
unsigned char empty[0] = {};
rxChar.setValue(empty, 0);
txChar.setValue(empty, 0);
// start advertising
BLE.advertise();
Serial.println("Bluetooth device active, waiting for connections...");
}
void loop() {
// poll for BLE events
BLE.poll();
}
void blePeripheralConnectHandler(BLEDevice central) {
// central connected event handler
Serial.print("Connected event, central: ");
Serial.println(central.address());
}
void blePeripheralDisconnectHandler(BLEDevice central) {
// central disconnected event handler
Serial.print("Disconnected event, central: ");
Serial.println(central.address());
}
void txCharSubscribed(BLEDevice central, BLECharacteristic ch) {
Serial.println("Subscribed");
}
void txCharUnsubscribed(BLEDevice central, BLECharacteristic ch) {
Serial.println("Unsubscribed");
}
void rxCharWritten(BLEDevice central, BLECharacteristic ch) {
const uint8_t* data = ch.value();
uint32_t len = ch.valueLength();
Serial.print("Got data:");
Serial.write(data, len);
txChar.setValue((uint8_t*)data, len);
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the BLE.setEventHandler calls for BLESubscribed and BLEUnsubscribed and follow event processing from BLE.poll(). Reproduce the Nordic UART Service example, then trace where characteristic subscription changes are detected. Done means both handlers are invoked when a central subscribes and unsubscribes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- arduino, cpp
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100