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

SERVICE HANDLE OF NUS

I am trying to determine the service handle of the nus example, to be able to verify that the central has turned on notifications.

I am using the sd_ble_gatts_value_get(m_conn_handle,  , &pval); function to read the attribute value and then test if for notifications enabled, but for the life of me cannot determine what it is?

I have found the characteristic add and found the p_nus->service_handle, but the reference is not valid, how do I access this handle to be able to do this test?

Herb

  • No one responded to this, but I found the handle, really obscure documentation and beyond sketchy examples.

    Now that I found this, and got it to compile, it does not return a value, what am I doing wrong here:

    if ( Device_Connected && filter_pointer == FILTER_LENGTH)
    {
    uint16_t length = 7u;
    uint8_t p_bull = NULL;
    ble_gatts_value_t pval;
    *pval.p_value = p_bull;

    err_code = sd_ble_gatts_value_get(m_conn_handle, m_nus.tx_handles.cccd_handle, &pval);
    uint8_t p_temp = *pval.p_value;
    if ( p_temp&0x01 )
    {
    do{
    err_code = ble_nus_data_send(&m_nus, ble_buffer, &length, m_conn_handle);
    if ((err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_NOT_FOUND))
    {
    APP_ERROR_CHECK(err_code);
    }
    } while (err_code == NRF_ERROR_RESOURCES);
    }
    }
    if(filter_pointer == FILTER_LENGTH){filter_pointer = false;}
    }

  • you can just handle BLE_NUS_EVT_COMM_STARTED (on notification enabled) and BLE_NUS_EVT_COMM_STOPPED (on notification disabled) event type from your registered nus callback.

    jing

  • Jing, thank you for your reply, can you show an example of an implementation, I cannot determine what to do at my current nordic skill level from your comment.

    Herb

  • \nRF5_SDK_17.0.2_d674dde\examples\ble_peripheral\ble_app_uart\main.c

    static void nus_data_handler(ble_nus_evt_t * p_evt)
    {
        if (p_evt->type == BLE_NUS_EVT_COMM_STARTED)
        {
            /* TX Characteristic notification enabled */
        }
        else if (p_evt->type == BLE_NUS_EVT_COMM_STOPPED)
        {
            /* TX Characteristic notification disabled */
        }

        :

    jing

Related