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
  • Hey.

    • Starting timer: You can check the BLE_GATTS_EVT_WRITE event to see when the cccd is written to 1 (Notifications enabled). Check the p_ble_evt->evt.gatts_evt.params.write.handle value. If this is the cccd handle of your characteristic, this means notifications are enabled. This is a good trigger to start sending data, because it means that the central is ready to receive notifications.

    • Stopping timer: You can check cccd writes here as well, to see if notifications are disabled. You should also stop on the event: BLE_GAP_EVT_DISCONNECTED

Reply
  • Hey.

    • Starting timer: You can check the BLE_GATTS_EVT_WRITE event to see when the cccd is written to 1 (Notifications enabled). Check the p_ble_evt->evt.gatts_evt.params.write.handle value. If this is the cccd handle of your characteristic, this means notifications are enabled. This is a good trigger to start sending data, because it means that the central is ready to receive notifications.

    • Stopping timer: You can check cccd writes here as well, to see if notifications are disabled. You should also stop on the event: BLE_GAP_EVT_DISCONNECTED

Children
No Data
Related