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

Not being able to completely transmit large string over BLE

Greetings!

I am using nRF52, SDK14.2, and NUS with MTU = 64.
I want to transmit 1000 byte string over BLE upon reception of any character to "nus_data_handler"
I have divided "main_buf" into 50 bytes data packets and am trying to send them over BLE.

Please refer to following code:

static void nus_data_handler(ble_nus_evt_t * p_evt)
{
    if (p_evt->type == BLE_NUS_EVT_RX_DATA)
    {
	uint32_t err_code; int i=0,j=0; uint16_t len = 50; uint8_t data_arr[50];
	char* main_buf = {"..."};  //1000 bytes of string data
	for (j=0;j<1000;j++)
		{
			data_arr[i] = main_buf[j];
			i++;
			if(i==len)
				{
					i=0;
					ble_nus_string_send(&m_nus, data_arr, &len); //transmits 50 byte packets over ble
				}
		}

    }
}

Problem: I can receive only partial string.
In nRFconnect app, I can receive only 4-string packets (200 bytes) out of 1000 bytes transmitted.
If uint16_t len = 5; uint8_t data_arr[5]; instead of length 50; I could receive only 7-string packets each of 5 bytes (=35 bytes received out of 1000bytes).

Tried with:

              do
                {
                    err_code = ble_nus_string_send(&m_nus, data_arr, &len);
                    if ( (err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_BUSY) )
                    {
                        APP_ERROR_CHECK(err_code);
                    }
                } while (err_code == NRF_ERROR_BUSY);

In nRFconnect: connection terminates by mentioning: Error 133 (0x85): GATT ERROR and Error 8 (0x08): GATT CONN TIMEOUT.

Please provide your view and suggestions!

Parents
  • Hi Sanket

    I strongly recommend you divide your packets into 20 byte packets, as this is the most efficient way to transfer large BLE strings.The errors you are experiencing are that the GATT client loses connection. You should make sure there are TX buffers available. You can call sd_ble_gatts_hvx until you get NRF_ERROR_RESOURCSES. When that happens, wait for BLE_GATTS_EVT_HVN_TX_COMPLETE before you call sd_ble_gatts_hvx again.  You can look at this case for some pointers on how to do this, however some of the code might be outdated. 

    Best regards,

    Simon

Reply
  • Hi Sanket

    I strongly recommend you divide your packets into 20 byte packets, as this is the most efficient way to transfer large BLE strings.The errors you are experiencing are that the GATT client loses connection. You should make sure there are TX buffers available. You can call sd_ble_gatts_hvx until you get NRF_ERROR_RESOURCSES. When that happens, wait for BLE_GATTS_EVT_HVN_TX_COMPLETE before you call sd_ble_gatts_hvx again.  You can look at this case for some pointers on how to do this, however some of the code might be outdated. 

    Best regards,

    Simon

Children
Related