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

Long write only writes 4 packets

Hello,

I'm implementing long write function to my project.

I managed to get it working, but i can't send more than 68 bytes of data. When i'm sending the data, I slice it into <18bytes chunks and send each chunk with correct offset, using "BLE_GATT_OP_PREP_WRITE_REQ" as sending type. When all the data is through i use this command to execute the write: "BLE_GATT_OP_EXEC_WRITE_REQ".

Now no matter how much i send (if it's more than 68 bytes), only 68 bytes come through. When i looked into what comes through i saw that only FIRST 4 packets are recieved, even thought i execute when all packets are sent.

Why are other packets lost?

Best regards, Nejc

  • I see that I have misunderstood you a bit then. Yes, it is possible to use e.g. authorization to receive data written to a characteristic, and then manually writing it to an offset with sd_ble_gatts_value_set, but you would need to keep track of the offset and make sure the data goes to the correct place.

    Let's go back to the original issue at hand. Can you confirm that you send a prepare write request, the sd_ble_gattc_write call returns NRF_SUCCESS, and that you receive a BLE_GATTC_EVT_WRITE_RSP for each packet you send? And the evt->gattc_evt.gatt_status of all those events are BLE_GATT_STATUS_SUCCESS?

  • Ah yes, i was only watching of my event handle returned NRF_SUCCESS, not the status. I thought that since i get right write event, i don't have gatt_status errors. But yeah, you were right all along, sorry we had to go such a long way :).

    After debugging i found out that i DO get "BLE_GATT_STATUS_ATTERR_PREPARE_QUEUE_FULL" after 4 packets.

  • Okay, then we're a bit closer at least. You need to verify that the buffer has enough space in it, and that you report this correctly in the memory request. Alternatively, you can send an execute when you get a BLE_GATT_STATUS_ATTERR_PREPARE_QUEUE_FULL, then continue sending more packets from where you left off.

  • There, now it works perfectly! I handle BLE_GATT_STATUS_ATTERR_PREPARE_QUEUE_FULL by sending execute like you said, and then continue sending packets. Thanks for your help. Best regards, Nejc

1 2 3