4 Replies Latest reply on Jun 2, 2017 9:07 AM by user_385543602

    Writing a single field to a GATT Server

    user_385543602

      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.

        • 1. Re: Writing a single field to a GATT Server
          Madhu Lakshmipathy

          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

          • 2. Re: Writing a single field to a GATT Server
            user_385543602

            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

            • 3. Re: Writing a single field to a GATT Server
              e.pratt_1639216

              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.

              • 4. Re: Writing a single field to a GATT Server
                user_385543602

                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.