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

Parents Reply Children
  • ah sorry, i accidentally marked your comment as answer.. No the sender doesn't get any errors. I write to reciever and then wait for BLE_GATTC_EVT_WRITE_RSP. Also, the buffer provided for longwrite is a bit bigger than the size of data i want to send.

  • The buffer needs to be big enough to contain all the data packets and their handles. See this table to see the layout of each packet. This means that you will have to account for 6 bytes of overhead per Prepare Write Request.

    That is what long writes (also called reliable writes) are about. You queue up a lot of write requests, then write them all at once. If you do not need this functionality, it is better to just send write commands with an offset. The upside of the feature is that you can choose to write to multiple characteristics at the same time, or to keep data consistent at all times.

    It is fairly strange that the write response does not generate any error though.

  • Yes, i've seen that table. I made a buffer that's 200 bytes big, and i want to send around 90 - 100 bytes of data, so the buffer should be big enough. Hmm, never thought about that, but i don't really need to write multiple characteristics at once.. Which command do i use then if i just want to update one characteristic, and write in it with offsets? Which parameter should i use instead of "BLE_GATT_OP_PREP_WRITE_REQ"?

    Yeah it's really strange there are no errors... I've been working on this problem for a few days now...

  • You can use BLE_GATT_OP_WRITE_REQ or BLE_GATT_OP_WRITE_CMD. Write requests are limited the same way as prepare write requests, in that you have to wait for a response before you can send the next one. But the response will return with important error codes, like if the characteristic needs security. Write commands can be queued, and depending on your role and the SoftDevice, you can send up to 6 of them per connection interval. So they are much faster than other writes.

  • Yes i normally used "BLE_GATT_OP_WRITE_REQ", but wanted to implement Long Writes. Since i can't use offsets with "BLE_GATT_OP_WRITE_REQ", do i have to handle char value update on my own? I mean, do i need to just send packets with my data, and when it's all through merge packets with offsets by 20 and manually update my characteristic value?

Related