cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

Anonymous
Not applicable

I'm trying to write to a BLE attribule handle from a GATT client to GATT server using CyBle_GattcWriteCharacteristicValue() function. This works fine if the attribute on the server has only a single field. But the function returns CYBLE_ERROR_INVALID_OPERATION error when the attribute has multiple fields.

For example: This works fine if the Attribute has single field...

        GATTCWriteReq.attrHandle = ATTR_HANDLE;

        GATTCWriteReq.value.len = 4;               //4 bytes

        GATTCWriteReq.value.val = (uint8_t*)&someValue;

        bleApiResult = CyBle_GattcWriteCharacteristicValue(cyBle_connHandle, &GATTCWriteReq);

The Attribute that I'm unable to write has 2 fields of 2 bytes. I have tried changing the GATTCWriteReq.value.len = 2 but it still does not work. I have also double checked that the attribute on the sever allows both read and write features.

Any suggestions?

Thank you for your help.

0 Likes
Reply
1 Solution
Anonymous
Not applicable

Hi e.pratt

Thank you for your response.

I think I figured out the issue. I was sending multiple write requests to the server. I observed that I was always getting the error on the second write request. I found that before sending the next write request, I need to wait till I receive CYBLE_EVT_GATTC_WRITE_RSP event (indicating that CyBle_GattcWriteCharacteristicValue() has successfully completed) for the previous write request.

With regards to GATTCWriteReq.value.len, yes it should be equal to the number of bytes writing.

Thanks.

View solution in original post

4 Replies
Anonymous
Not applicable

Quick update, on investigating further, I found that CYBLE_EVT_GATTC_WRITE_RSP is not not being generated indicating that write operation did not finish successfully. Is there anything that I might be missing?

0 Likes
Reply
Anonymous
Not applicable

Since it is giving you an "INVALID OPERATION" response when the function has multiple fields, it would indicate that you are:

1. Out of space; Either ram, heap, stack, etc. for some operation necessary to perform the write

2. You are not connected/Client or allowed to write at this time (not sure what other scenarios would allow a write characteristic call)

3. The function handle/structure being passed is invalid in some way (wrong handle perhaps? With multiple fields within an attribute, the write might want a handle specifying which field to write to)

Some suggestions to try:

Try writing a multiple-byte attribute and see if you can get that approach working for a single field. Then, once you get, say, a 4-byte attribute field write working, then split the single field into two fields to see what changes.

GATTCWriteReq.value.len should be equal to the number of bytes you are writing (in this case 4).

Worst case, you can set the attribute to a single field with multiple bytes of data, and just interpret/use it as if it was two fields? Not ideal, but a good fallback for having issues.

0 Likes
Reply
Anonymous
Not applicable

Hi e.pratt

Thank you for your response.

I think I figured out the issue. I was sending multiple write requests to the server. I observed that I was always getting the error on the second write request. I found that before sending the next write request, I need to wait till I receive CYBLE_EVT_GATTC_WRITE_RSP event (indicating that CyBle_GattcWriteCharacteristicValue() has successfully completed) for the previous write request.

With regards to GATTCWriteReq.value.len, yes it should be equal to the number of bytes writing.

Thanks.

View solution in original post

Anonymous
Not applicable

Hi pmegharaj,

I'm glad you figured it out. Best of luck with the rest of the project

0 Likes
Reply