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

I have a question about function 'ble_nus_data_send()'

Hello

I'm asking a question because there's a part that doesn't work well while using ble_nus_data_send().

There is a problem sending continuous data to the app using this function. (Only the first few are sent, and the rest are ignored.)

I've tested to send a simple count value.

char count_array[20];

int main(void)
{
    bool erase_bonds;
    uint32_t err_code;

    // Initialize.
    uart_init(); 
    log_init();
    timers_init();
    buttons_leds_init(&erase_bonds);
    power_management_init();
    ble_stack_init(); 
    gap_params_init();
    gatt_init();
    services_init(); 
    advertising_init(); 
    conn_params_init();
    peer_manager_init();

    // Start execution.
    NRF_LOG_INFO("Template example started.");
    printf("Template example started\n");
    advertising_start(erase_bonds);
    nrf_drv_clock_lfclk_request(NULL);

    err_code = nrf_crypto_init();
    APP_ERROR_CHECK(err_code);

    err_code = nrf_mem_init();
    APP_ERROR_CHECK(err_code);

    saadc_all_init();

    // Enter main loop.
    for (;;)
    {
        int test_count = 0;

        idle_state_handle();

        if(adc_value > 0)
        {
          sprintf(m_plain_text, "sensor value : %d", adc_value);
          crypt_ctr();

          //send to app test
          for(int i=0; i<length_app_encrypt; i++) //length_app_encrypt = 18
          {
            //test
            sprintf(count_array, "%d", test_count);
            uint16_t count_length = strlen(count_array);
            test_count++;

            err_code = ble_nus_data_send(&m_nus, &count_array, &count_length, m_conn_handle);
            if ((err_code != NRF_ERROR_INVALID_STATE) && 
                (err_code != NRF_ERROR_RESOURCES) &&
                (err_code != NRF_ERROR_NOT_FOUND) &&
                (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)) 
                {
                    APP_ERROR_CHECK(err_code);
                }

            NRF_LOG_RAW_INFO("test value : %s\n", count_array);
            NRF_LOG_FLUSH();
        }
    }
}

Values are output well from debug terminals. (0 to 17)
However, as a result of checking in the app, the count value is only output 0 to 5, and the rest is ignored.

                             

May I know the cause and solution of this problem?

Thank you.

Parents
  • Hello,

    I would think that there reason here could be that you are queueing data for transfer faster than you are sending it, leading to a full buffer - and a NRF_ERROR_RESOURCES error returned from ble_nus_data_send.
    However, with your current code you are discarding this error code, so you will never know if this actually happened.
    If it happens, you code just moves on to the next value, without accounting for the fact that the previous value was not sent. Please check to see if NRF_ERROR_RESOURCES is returned from ble_nus_data_send every time a number is not sent.

    If my suspicion is correct you could fix this by either implementing an error handling for the NRF_ERROR_RESOURCES that keeps the unsent values in another buffer (which also will likely overflow - depends on the speed of your data creation), or change connection parameters to increase throughput, or increase the HVX queue size.

    Best regards,
    Karl

  • Thank you!
    I fixed the value of 'NRF_SDH_BLE_GAP_EVENT_LENGTH' and solved it.

Reply Children
Related