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

How to send more than 20 bytes using sd_ble_gatts_hvx

Hello,

I am looking for a way to send more than 20 bytes by using 'sd_ble_gatts_hvx' function. I want to get the maximum debit that is in theory 6x20 bytes Do I just have to send the set the p_len parameter to 6x20, because i didn't succeed through this way! I am using the S110 firmware and the nRF51-Dongle Thanks for you help

  • Here a part of my code:

    attr_char_value.init_len= attr_char_value.max_len=20*6;
    attr_char_value.p_value   = encoded_initial_hrm;  where encoded_initial_hrm points a 20*6 byte vector
    

    I do a loop like as following if (p_hrs->conn_handle != BLE_CONN_HANDLE_INVALID):

    uint8_t i_packet=0; // variable to count the while increment
    uint8_t i_NRF_SUCCESS=0; // variable to count NRF_SUCCESS event
    hvx_params.handle = p_hrs->sequence0_handles.value_handle;
    hvx_params.type   = BLE_GATT_HVX_NOTIFICATION; 
    hvx_params.offset = 0;
    hvx_params.p_len  = &hvx_len;
    hvx_params.p_data = encoded_hrm1;	
    while(1)
    {
    err_code0 = sd_ble_gatts_hvx(p_hrs->conn_handle, &hvx_params);
    i_packet++;
    if (err_code0==NRF_SUCCESS) // only to count NRF_SUCCESS event
    {							
    i_NRF_SUCCESS++;		
    NULL;
    }
    if (err_code0==BLE_ERROR_NO_TX_BUFFERS)
    {
    break; 
    }
    else
    if(err_code0 == NRF_ERROR_INVALID_STATE || err_code0 == BLE_ERROR_GATTS_SYS_ATTR_MISSING)	
    {
    break;
    }
    previous_err_code0=err_code0;
    }
    

    That I see is I get an NRf_SUCCESS after my first sd_ble_gatts_hvx(...) call and after the second one I get already BLE_ERROR_NO_TX_BUFFERS. For me it seems that I only sent 20bytes and not 6x20bytes. Because when I get the ‘break’ because of the err_code0==BLE_ERROR_NO_TX_BUFFERS, I have i_NRF_SUCCESS =1 and i_packet=2; So I didn’t fill the TX BUFFER with 20x6 bytes... so how I can I be sure that by TX BUFFER is full of 20x6 bytes?

  • You cannot fill the 6 buffers in one move, you need to call sd_ble_gatts_hvx() 6 times. Before you send anything; does sd_ble_tx_buffer_count_get() return 6?

  • Thanks, err_code=sd_ble_tx_buffer_count_get(&p_count) returns me errorcode 0x000, and updates the p_count to 0x07!

  • Sorry. 0x07 is correct, but only 6 of the buffers are used for notifications. Your code looks like it should work, so I'm not sure what to suggest. Could you upload your complete project so I can have a look at it here? What version of SoftDevice and SDK are you using? How are you using the dongle? Master Control Panel?

  • Thanks, How can I upload my projet ? I use the s110_nrf51822_7.1.0_softdevice.hex with master control panel

    In my while loop the first sd_ble_gatts_hvx(p_hrs->conn_handle, &hvx_params) call returns NRF_SUCCESS (yeah!!) after the second sd_ble_gatts_hvx(p_hrs->conn_handle, &hvx_params) call returns me BLE_ERROR_NO_TX_BUFFERS. (my understanding is I succed in send 20 bytes). After getting this BLE_ERROR_NO_TX_BUFFERS, I update all the hvx_params and resend an sd_ble_gatts_hvx(p_hrs->conn_handle, &hvx_params) which returns sometimes a beautifull NRF_SUCCESS and sometimes still a BLE_ERROR_NO_TX_BUFFERS??? why do you have an idea? Why sometimes I update correctly the TX BUFFER and sometimes no?

Related