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

Long write error, GATT INVALID ATTR LEN

Good evening,

I am trying to implement queued write (long write) into ble_app_uart example. I am using s110_v7.1, nrf51822(pca10028), can not find version of sdk it is one of the older ones, probably sdk6.

This is how BLE events ar handled:

 case BLE_EVT_USER_MEM_REQUEST:
        
        mem_block.len = QUEUED_WRITE_BUFFER_SIZE;
        mem_block.p_mem = &queued_write_buffer[0];
        err_code = sd_ble_user_mem_reply(m_conn_handle, &mem_block);
					//simple_uart_putstring("User mem request \r\n");
						if (err_code != NRF_SUCCESS)
						{
							sprintf((char*)debug_string11,"ERROR USER_MEM_REQ\r\n");
							simple_uart_putstring(debug_string11);
						}
						else
						{
							sprintf((char*)debug_string11,"USER_MEM_REQUEST OK\r\n");
							simple_uart_putstring(debug_string11);
						}
        break;
			
     case BLE_EVT_USER_MEM_RELEASE:
					
        if ((p_ble_evt->evt.common_evt.params.user_mem_release.mem_block.p_mem == mem_block.p_mem)&&(p_ble_evt->evt.common_evt.params.user_mem_release.mem_block.len == mem_block.len))
        {
            //memory released do nothing. 
							//simple_uart_putstring("User mem released \r\n");
						sprintf((char*)debug_string13,"USER_MEM_REQUEST OK\r\n");
						simple_uart_putstring(debug_string13);
        }
					break;
					
   case BLE_GATTS_EVT_WRITE:
							//simple_uart_putstring("Evt Write \r\n");
			sprintf((char*)debug_string10,"BLE_GATTS_EVT_WRITE\r\n");
								simple_uart_putstring(debug_string10);
        break;

These are passed to the events:

#define QUEUED_WRITE_BUFFER_SIZE        350
static uint8_t queued_write_buffer[QUEUED_WRITE_BUFFER_SIZE];
static ble_user_mem_block_t mem_block;

This is what I receive in nrf sniffer:

image description

This is from nrf connect app in my tablet:

image description

Could not find what is the problem of error in dev zone, nor in the net. If there is lack of information let me know. Thank you.

-------------------------------------------------------UPDATE-----------------------------------------

Have found that I havent changed where I am puttin characteristics in tx_char_add and rx_char_add. I have them changed to:

//MODIFIED************************************************************************
attr_md.vloc              = BLE_GATTS_VLOC_USER;//BLE_GATTS_VLOC_STACK;
//********************************************************************************

//MODIFIED************************************************************************
   attr_char_value.max_len   = QUEUED_WRITE_BUFFER_SIZE;//BLE_NUS_MAX_RX_CHAR_LEN
 //********************************************************************************

Now I see that characteristics <20 and >20 size of bytes are sent without error. Unfortunately, if I receive something from pca10028 tablet do not recognise symbols. In addition to this, in nus service I have made that every received characteristic will be replied with somekind of response. Right now I do not receive any response from pca10028 if received characteristic exceeds 20 bytes. here are screenshot of tablet:

image description

this is my logg in UART:

image description

sniff of long write: was it successful???

image description

what are your oppinions why I do I receive those "? ? ? ?" instead of my reply? why I do not receive response in table exceeding 20 bytes?

  • Your sniff looks okay. Can't you just check if you received the data you write?

    "In addition to this, in nus service I have made that every received characteristic will be replied with some kind of response." Could you elaborate on this? What kind of a response? Are you sending a notification every time something is written?

    1. Hi, thank you for responsing. My bad for not explaining in a more detailed way. I see in debbuger that I receive <20B and >20B correctly with pca10028 board. But I do not receive the same data in android sent from pca10028. Actualy, I receive only one message in andoid it is "(0x)C0-07-00-00-D1-06-00-00-D1-06-00-00-D1-00-00-00-B1-06-00-00-00-00-00-00" whatever I am sending from board. Despite, it is longer or shorter than 20 B.

    2. I would like to pass characteristics which are <20B and >20B size to nus data handler. There I could process received data. How could I pass queued_write_buffer and buffer that is already being passed to nus_data_handler if one of those two was received?

    3. Yes, every time I receive something from android I send notification back. But now I see that is it not happening because >20B characteristics are not being passed to nus_data_handler.

    1. In addition to this, I see that just using ble_nus_send_string(&m_nus,debug_string6,30); will not send string at all. Can I send >20 using ble_nus_send_string? How could I perform queued write from pca10028 side?
  • Maybe it would easier to implement receiving and sending >20 B by spliting into 20bytes buffers? But then how should I receive data >20 in pca10028?

  • You should know which SoftDevice and SDK version you are using, please try to find out.

    Ok. So if I understand you correctly. The first problem you need to solve is how nus_data_handler() will handle the long write, it was not written to handle long writes so you have to modify it. Have you done any modifications?

    In S110 it is not possible to send notifications longer than 20 bytes.

Related