mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-11-22 05:00:55 +01:00
Add method to send notifications/indications with custom values (#63)
This commit is contained in:
parent
d793b1251e
commit
f841f030ae
2 changed files with 15 additions and 4 deletions
|
@ -397,6 +397,7 @@ void NimBLECharacteristic::indicate() {
|
||||||
NIMBLE_LOGD(LOG_TAG, "<< indicate");
|
NIMBLE_LOGD(LOG_TAG, "<< indicate");
|
||||||
} // indicate
|
} // indicate
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Send a notification.\n
|
* @brief Send a notification.\n
|
||||||
* A notification is a transmission of up to the first 20 bytes of the characteristic value.\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.
|
* @param[in] is_notification if true sends a notification, false sends an indication.
|
||||||
*/
|
*/
|
||||||
void NimBLECharacteristic::notify(bool is_notification) {
|
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) &&
|
if(!(m_properties & NIMBLE_PROPERTY::NOTIFY) &&
|
||||||
!(m_properties & NIMBLE_PROPERTY::INDICATE))
|
!(m_properties & NIMBLE_PROPERTY::INDICATE))
|
||||||
|
@ -421,9 +432,7 @@ void NimBLECharacteristic::notify(bool is_notification) {
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pCallbacks->onNotify(this);
|
m_pCallbacks->onNotify(this);
|
||||||
|
|
||||||
std::string value = getValue();
|
|
||||||
size_t length = value.length();
|
|
||||||
bool reqSec = (m_properties & BLE_GATT_CHR_F_READ_AUTHEN) ||
|
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_AUTHOR) ||
|
||||||
(m_properties & BLE_GATT_CHR_F_READ_ENC);
|
(m_properties & BLE_GATT_CHR_F_READ_ENC);
|
||||||
|
|
|
@ -84,6 +84,8 @@ public:
|
||||||
|
|
||||||
void indicate();
|
void indicate();
|
||||||
void notify(bool is_notification = true);
|
void notify(bool is_notification = true);
|
||||||
|
void notify(std::string value, bool is_notification = true);
|
||||||
|
|
||||||
size_t getSubscribedCount();
|
size_t getSubscribedCount();
|
||||||
|
|
||||||
NimBLEDescriptor* createDescriptor(const char* uuid,
|
NimBLEDescriptor* createDescriptor(const char* uuid,
|
||||||
|
|
Loading…
Reference in a new issue