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

Unable to receive full data over BLE

I am trying to receive a string of 708 characters via BLE. As BLE cap a maximum of 20 bytes per transmission, at the mobile app side I break the data to be send every 20 characters (each char is 1 byte as < 7F). The code at Nordic to receive the data is as follows:

uint8_t *buf = NULL;
size_t total_len = 0;
.
.
.
case BLE_GATTS_EVT_WRITE:
{ 
            ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
            size_t len = p_evt_write->len;
            buf = realloc(buf, total_len + len);
        	memcpy(buf + total_len, p_evt_write->data, len); 	
        	total_len += len;
        	SEGGER_RTT_printf(0, "current concatenated str: %s \n", buf);
        	SEGGER_RTT_printf(0, "total_len: %d \n", total_len);
        	if((p_evt_write->data[len-2] == 123) && (p_evt_write->data[len-1] == 123)){
        		 char* strall= malloc(total_len + 1);
        		 memcpy(strall, buf, total_len);
        		 strall[total_len] = 0;
        		 SEGGER_RTT_printf(0, "whole string is: %s \n", strall);
        		 total_len = 0;		
        	}

}

After receiving each round of characters, I concatenate it together to form back the original string. However, I am able to receive up till 429th character before it stops concatenating anymore new data. The 'buf' string either prints 0-429th characters then concatenate with some characters that was already previously received, or it just keep printing 0-429th character repeatedly even when new data is received (total_len keeps increasing till 708).

Why is this the case? Is there anything preventing Nordic from receiving the whole data? I will need to receive and concatenate all the characters.

Parents Reply
  • Oh then I'm sorry that I've promised quick fix, it looks like some deeper bug completely unrelated to the way how you store/handle bytes in this part of your code. Are you sure that if you perform single connection and single transfer that the issue persists and it's exactly at the 430th character regardless of buffer allocation method (static or dynamic)? This would be very very strange.

Children
No Data
Related