GATT prepare/execute write with NCS

Hi

I'm using the nRF Connect SDK v2.7.0 in central/client role to write data into a characteristic on a peer device.

I've seen that the function bt_gatt_write() automatically uses the prepare-/execute-write-requests when an offset is used or the data-length is bigger than the MTU size.

Are there also a publicly available GATT functions to use prepare- and execute-write-requests on purpose?

I'm asking this because these requests would also allow to prepare-writes for different handles and execute them all at once (which seems not possible with bt_gatt_write()).

Many thanks in advance.

Best regards

Remo

  • Hi

    Thank you for your fast answer.

    In which source/header file can I find the functions bt_gatt_write_prepare() and bt_gatt_execute_write()? I didn't find them in gatt.c/h.

    Best regards

  • I am sorry, I had to delete my previous reply and sorry for making your comment hang in there. I was wrong as the functions I mentioned were not publicly available to the application in the newer version of the sdk. the functions I mentioned aren’t available in the newer SDK version for direct use in applications. bt_gatt_write() does indeed handle cases where the data size exceeds the MTU by leveraging prepare and execute requests, but it doesn’t allow grouping multiple writes across different handles in a single transaction.

    If you need to work with multiple handles like this, One option is to set up your application to handle each bt_gatt_write() call in sequence—one per handle—and then wait for each write's callback to confirm completion before moving to the next. This would give you a managed sequence of writes, even though they’re individual transactions. This sounds like a compromise but an option nevertheless.

  • Even though it would be possible with a multi-handle prepare/execute write using the ATT protocol, there is no such defined method in the GATT standard using normal writes, as a client. This is only possible with so called "Reliable Writes" but in order to use these the characteristics must have the "Reliable Write" property enabled in their declaration. Zephyr doesn't support this feature as a client as far as I can see. In any case, it is a relatively inefficient method to transfer data using prepare/execute writes because all data is echoed back before committing. I would suggest to simply use a longer MTU instead which is nowadays supported on all popular platforms.

  • No problem. Thanks for your answer and the workaround.

Related