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

Return > 20 bytes (GATT_MTU) of data to GATT client

My GATT service measures a few values, and stores them (~ 100 bytes). When the GATT server (phone) requests data from a specific characteristic, I would like to return the stored values.

Since sending more than 20 bytes (GATT_MTU) requires multiple chunks, I'd like the server code to automatically update an index on each successive read by the client. The client issues successive reads until it received < GATT_MTU bytes, which indicates end of data.

I am unable to find a way to make the nRF51 return control into my code, upon a GATT read, such as via a callback. This is necessary to determine which chunk to send, and increment the index for the next anticipated read.

A callback is needed for any type of dynamic data to be returned, hence the post title.

I feel I must be missing something -- this seems like an obvious API call. Hope someone can point me to the right API call.

Parents
  • I think phone is GATT client, nRF51 is server.

    It is not straightforward to get some kind of "read request" callback. This may not be the best solution, but what i would do is enable notification on characteristic -> nRF51 does data processing -> send processed value to phone as notification. If you need confirmation after each read (it is not always needed, remember about retransmissions) you can use indication instead of notification. Some time ago i did something like this in different approach - i had two characteristics in service - index, and value. Value changes according to index value written to nRF51 by phone, and phone can read value after each succesfull write. but data change is immediate, so there is no processing delay.

Reply
  • I think phone is GATT client, nRF51 is server.

    It is not straightforward to get some kind of "read request" callback. This may not be the best solution, but what i would do is enable notification on characteristic -> nRF51 does data processing -> send processed value to phone as notification. If you need confirmation after each read (it is not always needed, remember about retransmissions) you can use indication instead of notification. Some time ago i did something like this in different approach - i had two characteristics in service - index, and value. Value changes according to index value written to nRF51 by phone, and phone can read value after each succesfull write. but data change is immediate, so there is no processing delay.

Children
No Data
Related