This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to check when the stack is ready to send notification?

Hi all,

I'm using two nRF51 DK to measure ADC input on peripheral side and translate it to central, based on Multilink example. One software timer is used to perform one ADC conversion every 1 sec, and send a notification to the central throug sd_ble_gatts_hvx(). Currently timer started and stopped by button press, I need to change it:

  • start timer, when connection is done AND notification is properly enabled;
  • stop timer, when notification disabled or connection is done.

What BLE events or functions should be used to get this done?

Currently I check:

  1. (m_conn_handle != BLE_CONN_HANDLE_INVALID) in timer handler - it doen's works when connection is done, handle still has the value

  2. err_code = sd_ble_gatts_hvx(m_conn_handle, &hvx_params);
     if (err_code != NRF_ERROR_INVALID_STATE && err_code !=     BLE_ERROR_GATTS_SYS_ATTR_MISSING)         
     {
         APP_ERROR_CHECK(err_code);
     }
    
Parents
  • Hi, Anders!

    Thank you, it works fine for cccd writes, but there is an error produced on the disconnection, althought BLE_GAP_EVT_DISCONNECTED is monitored. I get the 0x3004 error on the code:

    err_code = sd_ble_gatts_hvx(m_conn_handle, &hvx_params);
    if (err_code != NRF_ERROR_INVALID_STATE && err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING) {
    APP_ERROR_CHECK(err_code);
    }
    

    The problem typically appears on small timer period (I tested for 100 ms), when I reset central app. What is wrong here?

  • Since the central is off, the packets are not leaving the TX buffer. Adding more buffers will not help you. In your case, this error can be viewed as a symptom of a disconnect. The disconnect event will not happen before a certain amount of connection intervals have passed (this time is often defined as CONN_SUP_TIMEOUT in our SDK). You can ignore the error if you want, or you can pause the sending of packets until you receive a BLE_EVT_TX_COMPLETE

Reply Children
No Data
Related