mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-11-22 05:00:55 +01:00
Add conn_handle to NimBLECharacteristic::notify to send notification/indication to a specific client (#97)
Adds the ability to send notifications/indications to specific clients individually.
This commit is contained in:
parent
6fb26e3809
commit
e868f37135
2 changed files with 16 additions and 8 deletions
|
@ -411,9 +411,10 @@ void NimBLECharacteristic::indicate(const std::vector<uint8_t>& value) {
|
|||
/**
|
||||
* @brief Send a notification or indication.
|
||||
* @param[in] is_notification if true sends a notification, false sends an indication.
|
||||
* @param[in] conn_handle Connection handle to send individual notification, or BLE_HCI_LE_CONN_HANDLE_MAX + 1 to send notification to all subscribed clients.
|
||||
*/
|
||||
void NimBLECharacteristic::notify(bool is_notification) {
|
||||
notify(m_value.data(), m_value.length(), is_notification);
|
||||
void NimBLECharacteristic::notify(bool is_notification, uint16_t conn_handle) {
|
||||
notify(m_value.data(), m_value.length(), is_notification, conn_handle);
|
||||
} // notify
|
||||
|
||||
|
||||
|
@ -421,9 +422,10 @@ void NimBLECharacteristic::notify(bool is_notification) {
|
|||
* @brief Send a notification or indication.
|
||||
* @param[in] value A std::vector<uint8_t> containing the value to send as the notification value.
|
||||
* @param[in] is_notification if true sends a notification, false sends an indication.
|
||||
* @param[in] conn_handle Connection handle to send individual notification, or BLE_HCI_LE_CONN_HANDLE_MAX + 1 to send notification to all subscribed clients.
|
||||
*/
|
||||
void NimBLECharacteristic::notify(const std::vector<uint8_t>& value, bool is_notification) {
|
||||
notify(value.data(), value.size(), is_notification);
|
||||
void NimBLECharacteristic::notify(const std::vector<uint8_t>& value, bool is_notification, uint16_t conn_handle) {
|
||||
notify(value.data(), value.size(), is_notification, conn_handle);
|
||||
} // notify
|
||||
|
||||
|
||||
|
@ -432,8 +434,9 @@ void NimBLECharacteristic::notify(const std::vector<uint8_t>& value, bool is_not
|
|||
* @param[in] value A pointer to the data to send.
|
||||
* @param[in] length The length of the data to send.
|
||||
* @param[in] is_notification if true sends a notification, false sends an indication.
|
||||
* @param[in] conn_handle Connection handle to send individual notification, or BLE_HCI_LE_CONN_HANDLE_MAX + 1 to send notification to all subscribed clients.
|
||||
*/
|
||||
void NimBLECharacteristic::notify(const uint8_t* value, size_t length, bool is_notification) {
|
||||
void NimBLECharacteristic::notify(const uint8_t* value, size_t length, bool is_notification, uint16_t conn_handle) {
|
||||
NIMBLE_LOGD(LOG_TAG, ">> notify: length: %d", length);
|
||||
|
||||
if(!(m_properties & NIMBLE_PROPERTY::NOTIFY) &&
|
||||
|
@ -457,6 +460,11 @@ void NimBLECharacteristic::notify(const uint8_t* value, size_t length, bool is_n
|
|||
int rc = 0;
|
||||
|
||||
for (auto &it : m_subscribedVec) {
|
||||
// check if need a specific client
|
||||
if ((conn_handle <= BLE_HCI_LE_CONN_HANDLE_MAX) && (it.first != conn_handle)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
uint16_t _mtu = getService()->getServer()->getPeerMTU(it.first) - 3;
|
||||
|
||||
// check if connected and subscribed
|
||||
|
|
|
@ -84,9 +84,9 @@ public:
|
|||
void indicate();
|
||||
void indicate(const uint8_t* value, size_t length);
|
||||
void indicate(const std::vector<uint8_t>& value);
|
||||
void notify(bool is_notification = true);
|
||||
void notify(const uint8_t* value, size_t length, bool is_notification = true);
|
||||
void notify(const std::vector<uint8_t>& value, bool is_notification = true);
|
||||
void notify(bool is_notification = true, uint16_t conn_handle = BLE_HCI_LE_CONN_HANDLE_MAX + 1);
|
||||
void notify(const uint8_t* value, size_t length, bool is_notification = true, uint16_t conn_handle = BLE_HCI_LE_CONN_HANDLE_MAX + 1);
|
||||
void notify(const std::vector<uint8_t>& value, bool is_notification = true, uint16_t conn_handle = BLE_HCI_LE_CONN_HANDLE_MAX + 1);
|
||||
size_t getSubscribedCount();
|
||||
void addDescriptor(NimBLEDescriptor *pDescriptor);
|
||||
NimBLEDescriptor* getDescriptorByUUID(const char* uuid);
|
||||
|
|
Loading…
Reference in a new issue