Writing a single field to a GATT Server

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
ToVa_285016
Level 5
Level 5
100 replies posted 50 replies posted 50 questions asked

Hi,

   

I was wondering if it were possible to write to a single variable field in a GATT server without overwriting other fields.  For example, I have 'program, speed, brightness' fields in a characteristic - can I write to just one of those fields, and if so, how?

   

If not, would it not make more sense just to have a byte array instead of multiple fields?  It would accomplish the same thing.

   

Thank you in advance.

0 Likes
1 Solution
Anonymous
Not applicable

Hi,

   

Yes, You can have it as a array of bytes and the write the particular fields alone using CyBle_GattsWriteAttributeValue API. There the length and the offset can be given so that the selected fields alone are overwritten.

   

(Once the write comes from the client, the write call back is invoked in the server, from which the server accesses the data. Here, the CyBle_GattsWriteAttributeValue API is callled in order to write the received data to the GATT DB of the server)

   

Regards,

   

- Madhu Sudhan

View solution in original post

0 Likes
4 Replies
Anonymous
Not applicable

Hi,

   

Yes, You can have it as a array of bytes and the write the particular fields alone using CyBle_GattsWriteAttributeValue API. There the length and the offset can be given so that the selected fields alone are overwritten.

   

(Once the write comes from the client, the write call back is invoked in the server, from which the server accesses the data. Here, the CyBle_GattsWriteAttributeValue API is callled in order to write the received data to the GATT DB of the server)

   

Regards,

   

- Madhu Sudhan

0 Likes
ToVa_285016
Level 5
Level 5
100 replies posted 50 replies posted 50 questions asked

Hi,

   

As a follow up to this, how can I write a single field of a GATTS notificaiton to an Android device.  I cannot see how to get the device to realize that the data update is only for, say the second field of the characteristic.  I have tried to set the value.len to specify the offset, but the data is garbage on the Android side.  The only way that works to notify is to set both the len and actualLen to 1, but then my app cannot tell which of the fields the value is for.  I suppose the only other way would be to send an array of all 4 values and pick out the non-zero value on the other side, but I actually want the value to be able to be zero, so it would then be indistinguishable.

   

                tempHandle.value.val = &value;
                tempHandle.attrHandle = CYBLE_DMX_CONTROLLER_SYSVALS_CHAR_HANDLE;
                tempHandle.value.len = length;
                tempHandle.value.actualLen = 1;

   

                CyBle_GattsNotification(cyBle_connHandle, &tempHandle);

   

Thank you,

   

Tom

0 Likes
Anonymous
Not applicable

The notification functions on the entire characteristic/attribute, so afaik there is no way to indicate which field exactly changed. It should be a simple matter to compare it with a previous value on the client to see changed values however.

0 Likes
ToVa_285016
Level 5
Level 5
100 replies posted 50 replies posted 50 questions asked

I have set it up so that the read just replaces all of the field values every time, as the GATT server should have the most up to date values anyways.  Thanks for your comment.

0 Likes