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.

Related