Skip to content

Weird Behavior with v2.0 for the setValue() and notify() #314

Open

Description

@michaelboeding

Hey I'm basically just trying to set the value on a characteristic and then notify in a loop to transfer large amounts of data. In this case wifi networks. And that all worked before without issue but now in v2.0 it seems to be failing. It almost seems like it only ever calls the notify() once even though I am looping through it to transfer lots of data.

  this->txCharacteristic->setValue(fullData);
  this->txCharacteristic->notify();

I only ever see one debug out call for

I (92730) NimBLE: GATT procedure initiated: notify; 
I (92735) NimBLE: att_handle=36

This all worked before upgrading so maybe some changes to that? Or did the API somehow change for this? @h2zero

Activity

  1. michaelboeding commented on Mar 7, 2025

    @michaelboeding
    Author

    Seems I got this working by calling the following

    this->txCharacteristic->setValue(fullData);
    this->txCharacteristic->notify(fullData.data(), fullData.size());
    

    Not sure if this is intentional and I was just always calling it wrong or if there is something wrong here with the notify()

    This is 1.4

    /**
     * @brief Send a notification or indication.
     * @param[in] is_notification if true sends a notification, false sends an indication.
     */
    void NimBLECharacteristic::notify(bool is_notification) {
        notify(m_value.data(), m_value.length(), is_notification);
    } // notify
    
    
    /**
     * @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.
     */
    void NimBLECharacteristic::notify(const std::vector<uint8_t>& value, bool is_notification) {
        notify(value.data(), value.size(), is_notification);
    } // notify
    

    This is 2.2

    **
     * @brief Send a notification.
     * @param[in] connHandle Connection handle to send an individual notification, or BLE_HS_CONN_HANDLE_NONE to send
     * the notification to all subscribed clients.
     * @return True if the notification was sent successfully, false otherwise.
     */
    bool NimBLECharacteristic::notify(uint16_t connHandle) const {
        return sendValue(nullptr, 0, true, connHandle);
    } // notify
    
    /**
     * @brief Send a notification.
     * @param[in] value A pointer to the data to send.
     * @param[in] length The length of the data to send.
     * @param[in] connHandle Connection handle to send an individual notification, or BLE_HS_CONN_HANDLE_NONE to send
     * the notification to all subscribed clients.
     * @return True if the notification was sent successfully, false otherwise.
     */
    bool NimBLECharacteristic::notify(const uint8_t* value, size_t length, uint16_t connHandle) const {
        return sendValue(value, length, true, connHandle);
    } // indicate
    
  2. h2zero commented on Mar 12, 2025

    @h2zero
    Owner

    This should work the same way, the only difference now is that the stack reads the value of the characteristic via a callback when calling notify rather than directly sending the value from the call.

    There are templates in the header to handle sending vectors etc..

  3. michaelboeding commented on Mar 13, 2025

    @michaelboeding
    Author

    Weird - well I fixed the issue by directly calling them. I can try to debug more later and see why it doesn't work on the previous implementation vs the new.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions