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.

Reply
  • 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.

Children
  • Thanks for quick response

    Reliable write would work for us as we want to write data (which is more than 20 bytes long) to a characteristic using android app. For eg: "Nordic semiconductor application". This characteristic value should than be displayed on console.

    ble_app_uart is working fine for me. But it only displays 20 bytes no matter how much data we send.

    So what modifications should I make to this example and where to make it working for more than 20 bytes.

  • You will have to set BLE_NUS_MAX_TX_CHAR_LEN to something larger than 20.

  • I have increased MAX_TX_CHAR_LEN ..also added BLE_EVT_USER_MEM_REQUEST an passed pointer to mem buffer of size 100 ...changed ble_uart_code ..but still I see only 20 bytes on uart console output.

    Do I need to send data from peer (android app in chunks of 20 bytes ) .. for this to work properly...I have created a android for sending data.

  • I am not exactly sure on how to do this from the Android side, sorry. Your app should call beginReliableWrite(), proceed with multiple writeCharacteristic() calls with chunks of 20-byte, then end with an executeReliableWrite(). This should trigger a USER_MEM_REQUEST, and after some delay, a GATTS_EVT_WRITE followed by a USER_MEM_RELEASE event. You might have to set the "reliable_wr" flag in the char_ext_props field to 1 when adding the characteristic for Android to discover this functionality.

  • as per your suggestion I have set reliable_wr flag for android to detect and following the sequence you have suggested. But I have one doubt on nordic app side. I think I will have to modify on_write(): if ( (p_evt_write->handle == p_nus->rx_handles.cccd_handle) && (p_evt_write->len == 2) ) { if (ble_srv_is_notification_enabled(p_evt_write->data)) { p_nus->is_notification_enabled = true; } else { p_nus->is_notification_enabled = false; } } else if ( (p_evt_write->handle == p_nus->tx_handles.value_handle) && (p_nus->data_handler != NULL) ) { 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. }

    and data_handler function void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length) { for (int i = 0; i < length; i++) { simple_uart_put(p_data[i]); } simple_uart_put('\n'); }

    As per my understanding whatever mem_block we pass is populated in reliable write. So in on write function Can I just send contents of mem_block byte by byte to console using simple_uart_put ?

Related