CyBle_GattsErrorRsp example

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

cross mob
maze_1672671
Level 4
Level 4
First like received 25 replies posted 25 sign-ins

Hello all,

I would like to send a negative response to a write request, so I wrote:

case CYBLE_EVT_GATTS_WRITE_REQ: {

     CYBLE_GATTS_WRITE_REQ_PARAM_T * wrReqParam = (CYBLE_GATTS_WRITE_REQ_PARAM_T *) eventParam ;

     if (MY_PORT_CHAR_HANDLE == wrReqParam->handleValPair.attrHandle) {

CYBLE_GATTS_ERR_PARAM_T err = {

.attrHandle = wrReqParam->handleValPair.attrHandle,

.opcode = 1,

.errorCode = CYBLE_GATT_ERR_UNLIKELY_ERROR

} ;

          CYBLE_API_RESULT_T x = CyBle_GattsErrorRsp(cyBle_connHandle, &err) ;

          DBG_PRINTF("%d = CyBle_GattsErrorRsp\n", x) ;

     }

}

break ;    

the print result is 2 == CYBLE_ERROR_INVALID_OPERATION

I read this post Re: How to send an ATT Error response , but it has not an example

In the specification I found:

Immagine.png

Can I send an error? How?

0 Likes
1 Solution
Anonymous
Not applicable

Looks like the issue is with the opcode used, the below code works for me to generate the error response

                errrsp.attrHandle=CYBLE_CUSTOM_SERVICE_CUSTOM_CHARACTERISTIC_CHAR_HANDLE;//handle to which write was done

                errrsp.opcode= (uint8)CYBLE_GATT_WRITE_REQ;//opcode for error response

                errrsp.errorCode=CYBLE_GATT_ERR_INVALID_ATTRIBUTE_LEN ;//ATTr length error

               

                apiresult = CyBle_GattsErrorRsp(cyBle_connHandle,&errrsp);

               

                printf(" ERROR API RESULT %d \n",apiresult);

Thanks,

Ranjith

View solution in original post

0 Likes
3 Replies
Anonymous
Not applicable

Hello,

If the Server already responded with an opcode which is done by the stack in most scenarios, this this operation could be invalid.

I believe this is what you are seeing in your case.  Do you have airlogs for this scenario?

Thanks,

Ranjith

0 Likes

Hello Ranjith,

I don't have airlogs.

I think that the stack does not respond because I must invoke:

Immagine.png

If, inside CYBLE_EVT_GATTS_WRITE_REQ event, I don't call this function, the phone connected to me complains.

The doc says: This function has to be invoked in response to a valid Write Request, but, in some cases, I would like to send an error (the phone should retry later). How can I send an error?

Best regards

0 Likes
Anonymous
Not applicable

Looks like the issue is with the opcode used, the below code works for me to generate the error response

                errrsp.attrHandle=CYBLE_CUSTOM_SERVICE_CUSTOM_CHARACTERISTIC_CHAR_HANDLE;//handle to which write was done

                errrsp.opcode= (uint8)CYBLE_GATT_WRITE_REQ;//opcode for error response

                errrsp.errorCode=CYBLE_GATT_ERR_INVALID_ATTRIBUTE_LEN ;//ATTr length error

               

                apiresult = CyBle_GattsErrorRsp(cyBle_connHandle,&errrsp);

               

                printf(" ERROR API RESULT %d \n",apiresult);

Thanks,

Ranjith

0 Likes