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

Example doing a long BLE_GATT_OP_WRITE_REQ with sd_ble_gattc_write()?

Is there an example of using sd_ble_gattc_write() to do a long write?

I'm assuming I need to use BLE_GATT_OP_PREP_WRITE_REQ and BLE_GATT_OP_EXEC_WRITE_REQ.

devzone.nordicsemi.com/.../a00914.html shows using sd_ble_gattc_write() to do a "GATTC Characteristic or Descriptor Value Long Write", but this MSC isn't present in the 7.1.0 soft device.

I tried just writing the 28 bytes using sd_ble_gattc_write() and got back NRF_ERROR_DATA_SIZE. When I tried to do two BLE_GATT_OP_PREP_WRITE_REQs back to back I got a NRF_ERROR_BUSY on the second write.

Having to wait for the BLE_GATTC_EVT_WRITE_RSP event before doing additional writes is really going to complicate the code.

In this case I'm trying to implement the ANCS get app attributes command that requires writing a null terminated utf-8 string that is pretty much always >20bytes.

I am looking forward to a future softdevice that supports larger MTUs and fragmentation/reassembly, so needing long writes is much less likely.

Parents
  • Hi Clem,

    You are correct in the assumption that you have to use BLE_GATT_OP_PREP_WRITE_REQ and BLE_GATT_OP_EXEC_WRITE_REQ.

    The old documentation is still valid, although you would have to populate a struct instead of parameters in the call. The maximum length you can send with a prepare write request is 18 bytes, because two additional bytes in the request is used for offset. So you would have to split the long write up in 18 bytes bulks. And yes, you do need to wait for the RSP.

    If you use BLE_GATT_OP_WRITE_REQ or BLE_GATT_OP_WRITE_CMD, then the number of bytes you can write is 20.

    BR Pål

Reply
  • Hi Clem,

    You are correct in the assumption that you have to use BLE_GATT_OP_PREP_WRITE_REQ and BLE_GATT_OP_EXEC_WRITE_REQ.

    The old documentation is still valid, although you would have to populate a struct instead of parameters in the call. The maximum length you can send with a prepare write request is 18 bytes, because two additional bytes in the request is used for offset. So you would have to split the long write up in 18 bytes bulks. And yes, you do need to wait for the RSP.

    If you use BLE_GATT_OP_WRITE_REQ or BLE_GATT_OP_WRITE_CMD, then the number of bytes you can write is 20.

    BR Pål

Children
No Data
Related