Add method to send notifications/indications with custom values (#63)

This commit is contained in:
David Robertson 2021-12-29 03:11:37 +00:00 committed by GitHub
parent d793b1251e
commit f841f030ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View file

@ -397,6 +397,7 @@ void NimBLECharacteristic::indicate() {
NIMBLE_LOGD(LOG_TAG, "<< indicate");
} // indicate
/**
* @brief Send a notification.\n
* A notification is a transmission of up to the first 20 bytes of the characteristic value.\n
@ -404,8 +405,18 @@ void NimBLECharacteristic::indicate() {
* @param[in] is_notification if true sends a notification, false sends an indication.
*/
void NimBLECharacteristic::notify(bool is_notification) {
NIMBLE_LOGD(LOG_TAG, ">> notify: length: %d", getDataLength());
notify(getValue(), is_notification);
}
/**
* @brief Send a notification.\n
* A notification is a transmission of up to the first 20 bytes of the characteristic value.\n
* A notification will not block; it is a fire and forget.
* @param[in] is_notification if true sends a notification, false sends an indication.
*/
void NimBLECharacteristic::notify(std::string value, bool is_notification) {
size_t length = value.length();
NIMBLE_LOGD(LOG_TAG, ">> notify: length: %d", length);
if(!(m_properties & NIMBLE_PROPERTY::NOTIFY) &&
!(m_properties & NIMBLE_PROPERTY::INDICATE))
@ -422,8 +433,6 @@ void NimBLECharacteristic::notify(bool is_notification) {
m_pCallbacks->onNotify(this);
std::string value = getValue();
size_t length = value.length();
bool reqSec = (m_properties & BLE_GATT_CHR_F_READ_AUTHEN) ||
(m_properties & BLE_GATT_CHR_F_READ_AUTHOR) ||
(m_properties & BLE_GATT_CHR_F_READ_ENC);

View file

@ -84,6 +84,8 @@ public:
void indicate();
void notify(bool is_notification = true);
void notify(std::string value, bool is_notification = true);
size_t getSubscribedCount();
NimBLEDescriptor* createDescriptor(const char* uuid,