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.

CC2540: writing to large characteristic on CC2540?

Part Number: CC2540


Hi Team!

My customer has a question on writing to large characteristic (21 bytes) from an iOS application on CC2540.

Below is the concept my customer is trying to accomplish.

Currently they are trying to do a proof of concept for an idea that would involve writing to a characteristic from an iOS application. The goal was to be able to write from iOS to a characteristic that is larger than 20 bytes. They wrote an iOS app, and modified the firmware running on a 2540 to support a new service and characteristic. When writing to this characteristic from iOS, they are able to successfully write 20 bytes, but pushing this to 21 bytes causes an error saying that the values length is invalid. They are able to successfully read this characteristic.

 

They have verified that this happens in their own iOS app, and also the iOS app LightBlue. They have also confirmed on LightBlue on Android that the same occurs, they are able to read a 21 byte characteristic but not write.

 

The question is if you know if it is possible to write from iOS to a characteristic that is 21 bytes or more? Is there something that would need to be changed on the 2540 to support this?

 

Please let me know if you need any further information or clarification.

 

Thank you!

Peter

  • Hi Peter,

    What command are you using to write to this characteristic? In order to write a characteristic value using GATT_WriteCharValue, you are limited to a size of ATT_MTU-3. To write longer values, use GATT_WriteLongCharValue. See the GATT Client Sub-Procedure API Functions in the BLE API Guide for more information.
  • Hi Rachel,

    My customer has looked into the WriteLong you mentioned.. The issue is that they are seeing is that this does not seem to be supported on iOS/Android so I was wondering if we have any example apps or code for supporting this in regards to writing to the 2540?

    Thanks!

    Peter

  • Hello Peter,

    According to the iOS Core Bluetooth documentation, they do appear to support GATT long writes via the CBCharacteristicWriteType 'withResponse' option:
    developer.apple.com/.../cbcharacteristicwritetype
    "In general, when you write with a response, you can write a characteristic value that is longer than what is permitted when you write without a response."

    As to the device side changes, the processing of a long write is the same as a write w/o response with the following differences:
    length will represent the full length and the method will be ATT_EXECUTE_WRITE_REQ. You do not have to manage the offsets like you do for Blob Read operations.

    Note that the Prepare write queue size is defaulted to 5 elements, or 5 x 18 = 90 bytes. You can increase the size of the queue by calling GATTServApp_SetParameter with the GATT_PARAM_NUM_PREPARE_WRITES parameter.

    Best wishes
  • HI Jeff,

    Thanks for info!

    So my customer after looking through all of this information and trying some things out, they realized that being limited to 90 bytes will not work for their application.

    They've decided to come up with their own implementation of a blob write that will allow them to have larger transfers.

    Thanks for the support on this issue!

    Best Regards,

    Peter

  • Hello Peter,

    Glad to see they have a solution. For others, the 90 bytes is not a limitation, it is just the default prepare write queue size. As mentioned, the prepare write queue can be increased using the GATTServApp_SetParameter API with the GATT_PARAM_NUM_PREPARE_WRITES set to n where n is in units of 18 bytes. So, setting the queue size to 20 would allow 400 bytes.

    Best wishes