8000 Update remote characteristic to register for notify/indications (writ… · Netoperz/esp32-snippets@caa546a · GitHub
[go: up one dir, main page]

Skip to content

Commit caa546a

Browse files
committed
Update remote characteristic to register for notify/indications (write to 0x2902)
1 parent 14cdfb6 commit caa546a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

cpp_utils/BLERemoteCharacteristic.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ void BLERemoteCharacteristic::registerForNotify(
475475
BLERemoteCharacteristic* pBLERemoteCharacteristic,
476476
uint8_t* pData,
477477
size_t length,
478-
bool isNotify)) {
478+
bool isNotify), bool notifications) {
479479
ESP_LOGD(LOG_TAG, ">> registerForNotify(): %s", toString().c_str());
480480

481481
m_notifyCallback = notifyCallback; // Save the notification callback.
@@ -492,6 +492,12 @@ void BLERemoteCharacteristic::registerForNotify(
492492
if (errRc != ESP_OK) {
493493
ESP_LOGE(LOG_TAG, "esp_ble_gattc_register_for_notify: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
494494
}
495+
496+
uint8_t val[] = {0x01, 0x00};
497+
if(!notifications)
498+
val[0] = 0x02;
499+
BLERemoteDescriptor *desc = getDescriptorByUUID("0x2902");
500+
desc->writeValue(val, 2);
495501
} // End Register
496502
else { // If we weren't passed a callback function, then this is an unregistration.
497503
esp_err_t errRc = ::esp_ble_gattc_unregister_for_notify(
@@ -503,6 +509,10 @@ void BLERemoteCharacteristic::registerForNotify(
503509
if (errRc != ESP_OK) {
504510
ESP_LOGE(LOG_TAG, "esp_ble_gattc_unregister_for_notify: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
505511
}
512+
513+
uint8_t val[] = {0x00, 0x00};
514+
BLERemoteDescriptor *desc = getDescriptorByUUID("0x2902");
515+
desc->writeValue(val, 2);
506516
} // End Unregister
507517

508518
m_semaphoreRegForNotifyEvt.wait("registerForNotify");

cpp_utils/BLERemoteCharacteristic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class BLERemoteCharacteristic {
4444
uint8_t readUInt8(void);
4545
uint16_t readUInt16(void);
4646
uint32_t readUInt32(void);
47-
void registerForNotify(void (*notifyCallback)(BLERemoteCharacteristic* pBLERemoteCharacteristic, uint8_t* pData, size_t length, bool isNotify));
47+
void registerForNotify(void (*notifyCallback)(BLERemoteCharacteristic* pBLERemoteCharacteristic, uint8_t* pData, size_t length, bool isNotify), bool notifications = true);
4848
void writeValue(uint8_t* data, size_t length, bool response = false);
4949
void writeValue(std::string newValue, bool response = false);
5050
void writeValue(uint8_t newValue, bool response = false);

0 commit comments

Comments
 (0)
0