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!

Related