@@ -204,6 +204,11 @@ void BLERemoteCharacteristic::gattClientEventHandler(
204
204
// and unlock the semaphore to ensure that the requestor of the data can continue.
205
205
if (evtParam->read .status == ESP_GATT_OK) {
206
206
m_value = std::string ((char *)evtParam->read .value , evtParam->read .value_len );
207
+ if (m_rawData != nullptr )
208
+ free (m_rawData);
209
+
210
+ m_rawData = calloc (evtParam->read .value_len , sizeof (uint8_t ));
211
+ memcpy (m_rawData, evtParam->read .value , evtParam->read .value_len );
207
212
} else {
208
213
m_value = " " ;
209
214
}
@@ -475,7 +480,7 @@ void BLERemoteCharacteristic::registerForNotify(
475
480
BLERemoteCharacteristic* pBLERemoteCharacteristic,
476
481
uint8_t * pData,
477
482
size_t length,
478
- bool isNotify)) {
483
+ bool isNotify), bool notifications ) {
479
484
ESP_LOGD (LOG_TAG, " >> registerForNotify(): %s" , toString ().c_str ());
480
485
481
486
m_notifyCallback = notifyCallback; // Save the notification callback.
@@ -492,6 +497,12 @@ void BLERemoteCharacteristic::registerForNotify(
492
497
if (errRc != ESP_OK) {
493
498
ESP_LOGE (LOG_TAG, " esp_ble_gattc_register_for_notify: rc=%d %s" , errRc, GeneralUtils::errorToString (errRc));
494
499
}
500
+
501
+ uint8_t val[] = {0x01 , 0x00 };
502
+ if (!notifications)
503
+ val[0 ] = 0x02 ;
504
+ BLERemoteDescriptor *desc = getDescriptorByUUID (" 0x2902" );
505
+ desc->writeValue (val, 2 );
495
506
} // End Register
496
507
else { // If we weren't passed a callback function, then this is an unregistration.
497
508
esp_err_t errRc = ::esp_ble_gattc_unregister_for_notify (
@@ -503,6 +514,10 @@ void BLERemoteCharacteristic::registerForNotify(
503
514
if (errRc != ESP_OK) {
504
515
ESP_LOGE (LOG_TAG, " esp_ble_gattc_unregister_for_notify: rc=%d %s" , errRc, GeneralUtils::errorToString (errRc));
505
516
}
517
+
518
+ uint8_t val[] = {0x00 , 0x00 };
519
+ BLERemoteDescriptor *desc = getDescriptorByUUID (" 0x2902" );
520
+ desc->writeValue (val, 2 );
506
521
} // End Unregister
507
522
508
523
m_semaphoreRegForNotifyEvt.wait (" registerForNotify" );
@@ -603,4 +618,12 @@ void BLERemoteCharacteristic::writeValue(uint8_t* data, size_t length, bool resp
603
618
writeValue (std::string ((char *)data, length), response);
604
619
} // writeValue
605
620
621
+ /* *
622
+ * @brief Read raw data from remote characteristic as hex bytes
623
+ * @return return pointer data read
624
+ */
625
+ uint8_t * BLERemoteCharacteristic::readRawData () {
626
+ return m_rawData;
627
+ }
628
+
606
629
#endif /* CONFIG_BT_ENABLED */
0 commit comments