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

Long Attributes

Hi, I need to have long attributes. So I need 'Read Blob' operation for read and Queued writes ('Prepare Write' and 'Execute Write'). Does Soft Device for nrf51822 support mentioned commands?

Best regards, Artem Zemlyanukhin

Parents Reply Children
  • Hi,

    Thanks a lot for code example. I tested it, it works but not completely.

    At first to get additional information I added at the end of 'on_ble_evt' some code:

    if(p_ble_evt->header.evt_id == BLE_GATTS_EVT_WRITE) { sprintf(buffer, "Event 0x50: 0x%lx 0x%lx\r\n", p_ble_evt->evt.gatts_evt.params.write.len, *(uint8_t *)p_ble_evt->evt.gatts_evt.params.write.data); simple_uart_putstring(buffer); }

    I can't ability to use iPhone now, so I used TI usb-dongle (CC2540) with their software.

    Here is the sequence of my actions:

    1. Connect with device
    2. Send first 'Prepare Write Request' handle = 0x11, offset = 0, data = 01
    3. Send second 'Prepare Write Request' handle = 0x11, offset = 1, data = 02
    4. Send third 'Prepare Write Request' handle = 0x11, offset = 2, data = 03
    5. Send 'Execute Write Request'
    6. Send 'Read Request'

    Here is log:

    start Event: 0x10 Event: 0x12 memory requested, 0x1 Event: 0x2 Event: 0x50 Event 0x50: 0x0 0x0 Event: 0x3

    As you can see (also I sow it via debug) stack don't give me data in 'BLE_GATTS_EVT_WRITE' (len = 0, data = 0). But when I tried to read attribute after these operations, I received in 'Read Respnse' correct data: 01 02 03. In other words new attribute value was set, but I couldn't receive this new value in handler ('BLE_GATTS_EVT_WRITE' event). I viewed in debuger value of 'queued_write_buffer' (member of 'mem_block' union) passed as parameter in sd_ble_user_mem_reply. 'queued_write_buffer' had correct value: { 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, //first write (handler, offset, length, value) 0x11, 0x00, 0x01, 0x00, 0x01, 0x00, 0x02, //second write 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03 //third write }

    I tried to set attr_md.wr_auth = 1. In this case data in 'BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST' event handler is correct. I sent for example 3 PrepareWrite packets: - 2 bytes (0x01 and 0x02) with offset = 0 - 2 bytes (0x03 and 0x04) with offset = 2 - 2 bytes (0x05 and 0x06) with offset = 4

    and I received 4 (not 3) 'BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST' events: - for first write with correct data - for second write with correct data - for third write with correct data - extra event with data = 0, offset = 0, len = 0.

    when I sent 2 writes, I received 3 events. and in case of 1 write, I received 2 events. What does this extra event mean?

    1. What does it mean 'if (&p_ble_evt->evt.common_evt.params.user_mem_release.mem_block == &mem_block)' in 'BLE_EVT_USER_MEM_RELEASE' case? It's never true...

    2. As I read in your docemetation, stack send to application 'BLE_EVT_USER_MEM_REQUEST' event after first 'Prepare Write Request' but really it does it only after Send 'Execute Write Request'.

    3. Also my dongle didn't receive 'Prepare Write Response' packets, it received only 'Execute Write Response'. Is this possible? Or this bug of TI software?

  • Hi,

    Thanks a lot for code example. I tested it, it works but not completely.

    At first to get additional information I added at the end of 'on_ble_evt' some code:

    if(p_ble_evt->header.evt_id == BLE_GATTS_EVT_WRITE) { sprintf(buffer, "Event 0x50: 0x%lx 0x%lx\r\n", p_ble_evt->evt.gatts_evt.params.write.len, *(uint8_t *)p_ble_evt->evt.gatts_evt.params.write.data); simple_uart_putstring(buffer); }

    I can't ability to use iPhone now, so I used TI usb-dongle (CC2540) with their software.

    Here is the sequence of my actions:

    1. Connect with device
    2. Send first 'Prepare Write Request' handle = 0x11, offset = 0, data = 01
    3. Send second 'Prepare Write Request' handle = 0x11, offset = 1, data = 02
    4. Send third 'Prepare Write Request' handle = 0x11, offset = 2, data = 03
    5. Send 'Execute Write Request'
    6. Send 'Read Request'

    Here is log:

    start Event: 0x10 Event: 0x12 memory requested, 0x1 Event: 0x2 Event: 0x50 Event 0x50: 0x0 0x0 Event: 0x3

    As you can see (also I sow it via debug) stack don't give me data in 'BLE_GATTS_EVT_WRITE' (len = 0, data = 0). But when I tried to read attribute after these operations, I received in 'Read Respnse' correct data: 01 02 03. In other words new attribute value was set, but I couldn't receive this new value in handler ('BLE_GATTS_EVT_WRITE' event). I viewed in debuger value of 'queued_write_buffer' (member of 'mem_block' union) passed as parameter in sd_ble_user_mem_reply. 'queued_write_buffer' had correct value: { 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, //first write (handler, offset, length, value) 0x11, 0x00, 0x01, 0x00, 0x01, 0x00, 0x02, //second write 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03 //third write }

    I tried to set attr_md.wr_auth = 1. In this case data in 'BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST' event handler is correct. I sent for example 3 PrepareWrite packets: - 2 bytes (0x01 and 0x02) with offset = 0 - 2 bytes (0x03 and 0x04) with offset = 2 - 2 bytes (0x05 and 0x06) with offset = 4

    and I received 4 (not 3) 'BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST' events: - for first write with correct data - for second write with correct data - for third write with correct data - extra event with data = 0, offset = 0, len = 0.

    when I sent 2 writes, I received 3 events. and in case of 1 write, I received 2 events. What does this extra event mean?

    1. What does it mean 'if (&p_ble_evt->evt.common_evt.params.user_mem_release.mem_block == &mem_block)' in 'BLE_EVT_USER_MEM_RELEASE' case? It's never true...

    2. As I read in your docemetation, stack send to application 'BLE_EVT_USER_MEM_REQUEST' event after first 'Prepare Write Request' but really it does it only after Send 'Execute Write Request'.

    3. Also my dongle didn't receive 'Prepare Write Response' packets, it received only 'Execute Write Response'. Is this possible? Or this bug of TI software?

  • For completeness, I'll try to answer these questions separately:

    1. This is to be expected, as it is the Execute Write event, as you can see in the op field of ble_gatts_evt_write_t. This event will never have a length or a value, and if you need to see the values written, you'll have to either parse the memory buffer you provided yourself (see the format description in the softdevice headers) or use sd_ble_gatts_value_get() as you've done.

    2. This extra write is the Execute Write.

    3. This is actually a bug in my code that I didn't notice when testing. The intention was just to see that the same memory area was released afterwards, but to check this, you have to compare the actual memory pointer, i.e. p_data field of the memory block. However, since the memory allocation is static anyway, it doesn't really matter in my case.

    4. See my comment on your other reply below.

    5. This shouldn't be possible. When I sniff the link, I can see responses going over the air. Not sending such responses would be a spec violation, and trigger a GATT timeout, most likely causing a disconnect, so I believe this must be a bug in the TI tool.

  • Hi Ole,

    My project needs long write and I would like to start with the example code you provided: ble_app_lbs-long-write.zip. Unfortunately when I click it, it says "This Page is Unavailable". Could you send an working link to this file please? Thanks, Michael

Related