This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

long write samples

Hi All,

Are there any updated examples for nrf51822 for writing long charecteristics. My Application has to receive more than 20 bytes at a time and send over uart.

I am using experimental/ble_app_uart as starting point. I tried modifying the on_write function in service to check

if(p_evt_write->op == BLE_GATTS_OP_EXEC_WRITE_REQ_NOW) {
if ((p_evt_write->handle == p_nus->tx_handles.value_handle)) { p_nus->data_handler(p_nus, p_evt_write->data, p_evt_write->len); } else { // Do Nothing. This event is not relevant to this service. } }

But not getting anything on console. Without any modification app works fine for 20 bytes write. Even If send more than 20 bytes from android app it prints only 20 bytes.

Also my app requirement is to receive variable length writes from client to server.

What/Where changes needs to be made to make it working for writing more than 20 bytes ?

Am new to BLE development. Trying to learn by doing.

Thanks in Advance

Parents
  • I think you might be confusing long writes and long MTU.

    Long writes, also called "Reliable writes" or "Queued Writes", allows you to reliably and simultaneously write multiple <=20-byte chunks to a single or multiple characteristic(s)/descriptor(s). It does not allow you to transfer more data per connection event than other functions. (There are some restrictions in peer memory, and you are not allowed to have overlapping regions.) See here for some MSCs.

    If you want to send more than 20 bytes, you will have to break it down into chunks. If you need to write all the chunks at the same time (i.e. you want to update some data display that continuously reads more than 20 bytes of data each update) you can use reliable writes. If you want to enable/disable multiple CCCDs you can use reliable writes. However, if you need to send more than 20 bytes per packet, that is not currently possible with the Nordic SoftDevices.

  • Hello, I have tried parsing the mem_block we are passing to SD. But getting confused on the parser implementation. I have tried different methods but I am not getting result. Referring to the user mem layout given here

    But I am getting inconsistent results. If I read length of memblock it shows proper value for less than 20 bytes value but above 20 bytes it shows same value.

    This is my understanding of user mem layout. So SD writes total value provided to it in chunks to user_mem_block. In case of long write to same characteristic with same handle but with increasing offset changed. So parser we will have to read first chunk then move chunk bytes ahead ..and check handle value again read chunk and so on till we get BLE_GATT_HANDLE_INVALID. I implemented a parser like this but didn't get proper result.

    Then I just printed the contents of mem_queue.I was getting proper values till 35-36 bytes but then again some random bytes then remaining bytes.

    case BLE_GATTS_EVT_WRITE:
           								
    					simple_uart_putstring("In Write Event\n\r");
    
    					if (p_ble_evt->evt.gatts_evt.params.write.op == BLE_GATTS_OP_EXEC_WRITE_REQ_NOW)
    					{
    						  simple_uart_putstring("In Write Req Now Op\n\r");	
    						  int i;
    							for (i = 0; i < MEM_BLOCK_SIZE ; i++)
    							{
    								simple_uart_put(m_mem_block.p_mem[i]);
    							}
    							
    					}
    					simple_uart_put('\n');
    					simple_uart_put('\r');
            break;
    

    If you can give me a simple illustration of a parser then it would be great. Forgot to mention I am using dongle running MCP firmware to send long write values over BLE.

    Please ignore if there are any typos (I haven't had much sleep in last 2 days).

Reply
  • Hello, I have tried parsing the mem_block we are passing to SD. But getting confused on the parser implementation. I have tried different methods but I am not getting result. Referring to the user mem layout given here

    But I am getting inconsistent results. If I read length of memblock it shows proper value for less than 20 bytes value but above 20 bytes it shows same value.

    This is my understanding of user mem layout. So SD writes total value provided to it in chunks to user_mem_block. In case of long write to same characteristic with same handle but with increasing offset changed. So parser we will have to read first chunk then move chunk bytes ahead ..and check handle value again read chunk and so on till we get BLE_GATT_HANDLE_INVALID. I implemented a parser like this but didn't get proper result.

    Then I just printed the contents of mem_queue.I was getting proper values till 35-36 bytes but then again some random bytes then remaining bytes.

    case BLE_GATTS_EVT_WRITE:
           								
    					simple_uart_putstring("In Write Event\n\r");
    
    					if (p_ble_evt->evt.gatts_evt.params.write.op == BLE_GATTS_OP_EXEC_WRITE_REQ_NOW)
    					{
    						  simple_uart_putstring("In Write Req Now Op\n\r");	
    						  int i;
    							for (i = 0; i < MEM_BLOCK_SIZE ; i++)
    							{
    								simple_uart_put(m_mem_block.p_mem[i]);
    							}
    							
    					}
    					simple_uart_put('\n');
    					simple_uart_put('\r');
            break;
    

    If you can give me a simple illustration of a parser then it would be great. Forgot to mention I am using dongle running MCP firmware to send long write values over BLE.

    Please ignore if there are any typos (I haven't had much sleep in last 2 days).

Children
No Data
Related