This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

GATT_WriteCharValue length error

Other Parts Discussed in Thread: CC2540

Hi All, 

I use GATT_WriteCharValue for writing a characteristic value from the client side. The strange thing is when I set the "len" field of the request struct to greater than 1, always get length error. The current value of len is the same as the lenght of the appropriate characteristic value. 

Have you ever tried anything like this or do you have any suggestions?

Thanks,

Gergo

  • It is not the same as yours but check this behavior this user was noticing, perhaps will give you a clue. bye.

    http://e2e.ti.com/support/low_power_rf/f/538/t/147223.aspx

  • Hi Kazola,

    Thanks for you suggestion, but unfortunately I haven't found anything in our source which is inappropriate according to this thread.

    BR,

    Gergo

  • Hi Gergo,

    When do you get the error, when you compile? 

    Gergo Zsiak said:
    as the lenght of the appropriate characteristic value

    Could you post the declaration of the "appropriate" value,

    BR

  • Hi Nick,

    The error appears at run time, when the write operation is requested.  The setting of length is done by calling 

    req.len = SIMPLEPROFILE_CHAR2_LEN;

    where SIMPLEPROFILE_CHAR2_LEN is the same macro which is used in the definition of the attribute table. Of course, the req.handle is set to the corresponding handle. My colleague tested it, and said that the request is sent only if req.len is set to 1, otherwise fails. I'll also test this part of the software soon, but until that I wanted to ask others if anybody has ever experienced error like this.

    Thanks,

    Gergo

     

  • Hi Gergo,

    I meant the actual value you are trying to write, for example 2 bytes req.value[0] and req.value[1]. Have you done changes in the simpleGATT profile for characteristic value 2? I was thinking since the default size of simpleProfileChar2 is one byte.

    BR

  • Hi Nick,

    Yes, we've made some changes, for example length and rights of charvalues. I'll test it in a few days, then write again.

    BR,

    Gergo

  • Hi Nick,

    Currently I am testing this part of our software, and for me the write response says error 13, which is "The attribute value length is invalid for the operation." according to the Vendor Specific HCI guide.

    The code is the following (with the most neccessary comments):

    uint8 status; 

            attWriteReq_t req;        

            req.handle = charvHandles[1]; // appropriate charv handle

            req.len = SIMPLEPROFILE_CHAR2_LEN; // =16

            osal_memcpy(req.value, &lastTime, sizeof(lastTime)); // lastTime is a uint32 variable, and we want to send only this data in this case

            for(int i=sizeof(lastTime); i<SIMPLEPROFILE_CHAR2_LEN;++i) // fill the remaining bytes with zero

                req.value[i] = 0;

            req.sig = 0;

            req.cmd = 0;

            status = GATT_WriteCharValue(connHandle, &req, taskId);

    In addition the value of "status" is SUCCESS after the write request.

     

    Can you see any problems here?

     

    Thanks,

    Gergo

  • Hi Gergo,

    I found similar length related errors when trying to reproduce the keyfob application behavior some time ago, since the handles changes in the new version of the stack but I did not notice this until I was trying to program the cc2540. Have you checked this?

    http://e2e.ti.com/support/low_power_rf/f/538/p/134385/487693.aspx#487693

    :)

  • Hi Kazola,

    Thanks for your reply, but I don't think it's the problem. After GAP connection has been established, I find the charvalues by their UUIDs, and store their handles. Therefore I'm pretty sure that they're correct. Furtheremore, I would expect other kind of error when the handle is incorrect.

    BR,

    Gergo

  • I've performed some othert tests, too, here are the parameters and the results:

    • req.len=SIMPLEPROFILE_CHAR2_LEN; actual data written: 4 bytes FAIL
    • req.len=1; actual data written: 1 bytes OK
    • req.len=4; actual data written: 4 bytes FAIL

    I've also tried to fill all of the req.value array with zeros (not only the first SIMPLEPROFILE_CHAR2_LEN bytes, but 20) after the useful bytes.

     

    Do you have any ideas?

     

    BR,

    Gergo

  • Any suggestions?

    Thanks,

    Gergo

  • Some useful information would be highly appreciated. If this kind of error keeps on, I can't do anything but send data byte-by-byte, which is absolutely ugly (and, of course, only a workaround knowing that the API should be able to send more bytes at a time).

    Thanks,

    Gergo

  • The service that you are writing to is most likely set up to only accept writes with a data length of 1-byte.

    For example, the simpleGATTservice included in the SimpleBLEPeripheral contains two writeable characteristics (the first and third characteristics in the service). When a write request is received by the service, the callback function simpleProfile_WriteAttrCB gets called. In the function you will see the write gets validated. One of the checks in the function you will see is the following:

              if ( len != 1 )
              {
                status = ATT_ERR_INVALID_VALUE_SIZE;
              }

    This is why you are getting an error returned. In order to allow writes with length greater than 1-byte, you will need to:

    (1) Change the variable type of the characteristic value. Currently the value is uint8, so it would not be capable of storing four bytes of data.

    (2) Change the validation check in the simpleProfile_WriteAttrCB to allow for different length values.

    (3) Rebuild the code.

  • Hi Willis,

    The length check was the problem, now it works fine. Thanks for your help!

    BR,

    Gergo

  • Hi Will,

    I face the same problem with Gergo, I change the code by your advice, now I can send 4 bytes to peripheral device, but the problem is that only the first byte is changed even I send four different value, the rest three bytes ramain the old value. I am using Btool to read and write a 4 byte value in the profile. I changed the simpleProfile_WriteAttrCB() function, any other function I have to change?

  • Hi Gergo,

    I am facing the same problem with you, now my situation is that, when I modify the code by will's suggestion, I can send 4 bytes to peripheral device, but only the first byte is change, I want to know which part of the profile you had changed to fix your problem if you do not mind, I only change the simpleProfile_WriteAttrCB() function.

    Thanks and regards.

  • Hi Xiaochuan,

    My first guess is that you only set the first byte of the characteristic value. Do you copy these 4-byte array with osal_memcopy or byte-by-byte inside a loop?

    BR,

    Gergo

  • Hi Gergo,

    just like waht you said, I did not copy all the information to the message, that is the problem, now I already fix it, it works, Thank you

  • Hello,

    I'm doing the same.  The BLE central app app writes a 1 byte value when pressing joystick-up.  This works fine.  When I change the write to a length other than 1, I receive an error response with error code ATT_ERR_INVALID_VALUE_SIZE. 

    Has anyone else encountered this or know of a solution?

    Regards,

    Todd

  • Hi Todd,

    Have you set the length of the charv in the GATT profile definition? And the part of code where the length is checked (see previous page, verified answer)? 

    BR,

    Gergo

  • Gergo,

    Yes thanks and apologies, it is resolved.  I did not see the entire thread until after I posted.

    Regars,

    Todd

  • Hello Willis1,

    Nice to see your post~

    I am following simpleBLEPeripheral example on TI-CC2650 dev kit for BLE application. I am under the process of BLE communication between peripheral-central. I tried your suggested method (3 points in previous post) to send more than one byte to peripheral from central but its still working for only 1 byte as default. Please suggest, where I need to modify simpleBLEPeripheral to be working for sending the data more than a byte. I am confusing the actual code part to be modified for this.

    Thanks n Regards