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

Maximum data that can be sent at once

Hello ,

I am using a Laird's BL651 module that has a nRF52810 chipset. I have modified the ble_app_uart example to take a command from Rx characteristic and send a response notification as a string on the Tx characteristic. This I am doing with the nRF Connect app and I have removed the UART part i.e. there is no uart involvement in the functionality, the data is written in app and received over BLE and the response is also posted over the BLE.

Now that i am able to send a string say "Hello World" as a response, I wanted to know what is the maximum amount of data that i can send to the phone app at once. My ideal situation is to send a data of around 20KB to the phone app and I am pretty sure it cannot be done in a single shot.

So what is the highest value of data that I can send in a single shot and how do I send the next set of data?

Please let me know about the same so that i can come to know about how to deal with this.

Thanks & Regards

Sudeep R J

Parents
  • Hi,

    Simply:

    1. Call sd_ble_gatts_hvx() until NRF_ERROR_RESOURCES.
    2. Wait for BLE_GATTS_EVT_HVN_TX_COMPLETE event.
    3. Repeat from 1.

    You may find the following useful:
    https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s140.api.v6.0.0/group___b_l_e___g_a_t_t_s___f_u_n_c_t_i_o_n_s.html?cp=3_4_3_3_2_4_2_4#ga313fe43c2e93267da668572e885945db

    Note that you may increase the size of the individual packets by first exchange maximum supported packet size, it may also be possible to change physical on-air data rate if supported by both peers.

    You may find the following reading useful:
    https://www.novelbits.io/bluetooth-5-speed-maximum-throughput/
    https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.3.0/ble_sdk_app_att_mtu.html?cp=5_1_4_2_1_0 

    Best regards,
    Kenneth

  • Hey Kenneth,

    Its nice to be talking to you again after we discussed about sending a string over BLE and with your suggestions i could implement it using ble_app_uart example after eliminating the uart part in it.

    Now as you have suggested, I have written a data handler such that once the data is written in Rx characteristic it raises a BLE_NUS_EVT_RX_DATA event data and then whatever the data is written on Rx characteristic that is sent back on Tx characteristic as a notification. I am attaching the code below.

    static void nus_data_handler(ble_nus_evt_t *p_evt)
    {
      
      if(p_evt->type == BLE_NUS_EVT_RX_DATA)
      {
        uint32_t err_code;
       
        static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
        for(int i=0;i<8;i++)
        {
          data_array[i] = p_evt->params.rx_data.p_data[i];
        
        }    uint16_t length = sizeof(data_array) ;
        
       if(data_array != NULL )
       {
          err_code = ble_nus_data_send(&m_nus, data_array , &length, m_conn_handle);
          if(err_code != NRF_SUCCESS)
          {
            APP_ERROR_CHECK(err_code);
         }
         
       }
      }
      if(p_evt->type == BLE_NUS_EVT_TX_RDY)
         {
           uint32_t err_code;
           static uint8_t data_array[100] = "20384638290182635478291734527193764524373926353426892735344252743834624562845245178283645";
           static uint8_t data_array2[20];
           for(uint8_t j=i;j<i+20;i++)
           {
             data_array2[j]=data_array[j];
             
           } 
           uint16_t length = sizeof(data_array2);
            err_code = ble_nus_data_send(&m_nus, data_array2 , &length, m_conn_handle);
           if(err_code != NRF_SUCCESS)
          {
            APP_ERROR_CHECK(err_code);
         }
         }
    }    
    Here the i in the BLE_NUS_EVT_TX_RDY event is a global static variable that is used to track the number of elements in the array that are sent. Once this data is written then there will be a BLE_GATTS_EVT_HVN_TX_COMPLETE even raised and the handler for that in the ble_nus.c is as follows

    /**@brief Function for handling the @ref BLE_GATTS_EVT_HVN_TX_COMPLETE event from the SoftDevice.
     *
     * @param[in] p_nus     Nordic UART Service structure.
     * @param[in] p_ble_evt Pointer to the event received from BLE stack.
     */
    static void on_hvx_tx_complete(ble_nus_t * p_nus, ble_evt_t const * p_ble_evt)
    {
        ret_code_t                 err_code;
        ble_nus_evt_t              evt;
        ble_nus_client_context_t * p_client;
    
        err_code = blcm_link_ctx_get(p_nus->p_link_ctx_storage,
                                     p_ble_evt->evt.gatts_evt.conn_handle,
                                     (void *) &p_client);
        if (err_code != NRF_SUCCESS)
        {
            NRF_LOG_ERROR("Link context for 0x%02X connection handle could not be fetched.",
                          p_ble_evt->evt.gatts_evt.conn_handle);
            return;
        }
    
        if (p_client->is_notification_enabled)
        {
            memset(&evt, 0, sizeof(ble_nus_evt_t));
            evt.type        = BLE_NUS_EVT_TX_RDY;
            evt.p_nus       = p_nus;
            evt.conn_handle = p_ble_evt->evt.gatts_evt.conn_handle;
            evt.p_link_ctx  = p_client;
    
            p_nus->data_handler(&evt);
        }
    }
     So this handler will lead to nus_data_handler and the second part of nus_data_handler function is written for the same. It checks for BLE_NUS_EVT_TX_RDY event and transmits the array. This is how the program should work. But when I check this on nRF connect app, when I write data to the Rx characteristic then the result is as in the screenshot attached.

    So why is the notification not getting updated to the next set of values that I am sending in the BLE_NUS_EVT_TX_RDY event?

    Also according to the code written for first event it should give me only the value that i entered but it gives me a H appended with the value I wrote, for example as you can see in the screenshot i have entered 10 and i am notified with 10H. This H is appended to all the values that i write.

    So what is going wrong in this code? I want to send around 20KB of data and the dummy array that I have taken is not notified after the data is written.

    Kindly help me with this

    Thank you

  •  I dont know why the screenshot did not show up in the above reply. Attaching it here.

  • Hello, 

    Am I getting a reply for this?

    Its been a long time i have been waiting for this.

    Please do help me as soon as possible.

  • I suggest to add nrf_log so you may output events, data and length field(s) here. Then you can see if the events occur in the sequence you expect and if there are any error codes when sending the data with a specified length.

Reply Children
No Data
Related