Skip to content

Commit

Permalink
Receive GATT characteristic updates in BTStackLib (#2241)
Browse files Browse the repository at this point in the history
Fixes #2231
  • Loading branch information
earlephilhower authored Jun 24, 2024
1 parent fdc361a commit 1357e4a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libraries/BTstackLib/src/BTstackLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,10 @@ const gatt_client_characteristic_t * BLECharacteristic::getCharacteristic(void)
return &characteristic;
}

gatt_client_notification_t *BLECharacteristic::getNotifier() {
return &notify;
}


BLEService::BLEService(void) {
}
Expand Down Expand Up @@ -703,6 +707,7 @@ int BTstackManager::writeCharacteristicWithoutResponse(BLEDevice * device, BLEC
}
int BTstackManager::subscribeForNotifications(BLEDevice * device, BLECharacteristic * characteristic) {
gattAction = gattActionSubscribe;
gatt_client_listen_for_characteristic_value_updates(characteristic->getNotifier(), gatt_client_callback, device->getHandle(), (gatt_client_characteristic_t*) characteristic->getCharacteristic());
return gatt_client_write_client_characteristic_configuration(gatt_client_callback, device->getHandle(), (gatt_client_characteristic_t*) characteristic->getCharacteristic(),
GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION);
}
Expand All @@ -713,6 +718,7 @@ int BTstackManager::subscribeForIndications(BLEDevice * device, BLECharacteristi
}
int BTstackManager::unsubscribeFromNotifications(BLEDevice * device, BLECharacteristic * characteristic) {
gattAction = gattActionUnsubscribe;
gatt_client_stop_listening_for_characteristic_value_updates(characteristic->getNotifier());
return gatt_client_write_client_characteristic_configuration(gatt_client_callback, device->getHandle(), (gatt_client_characteristic_t*) characteristic->getCharacteristic(),
GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NONE);
}
Expand Down
2 changes: 2 additions & 0 deletions libraries/BTstackLib/src/BTstackLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ extern "C" {

class BLECharacteristic {
private:
gatt_client_notification_t notify;
gatt_client_characteristic_t characteristic;
UUID uuid;
public:
Expand All @@ -93,6 +94,7 @@ extern "C" {
bool matches(UUID * uuid);
bool isValueHandle(uint16_t value_handle);
const gatt_client_characteristic_t * getCharacteristic();
gatt_client_notification_t *getNotifier();
};

class BLEService {
Expand Down

0 comments on commit 1357e4a

Please sign in to comment.