1.2.2.1.2.4.12 GATTC_Write
C
uint16_t GATTC_Write(uint16_t connHandle, GATTC_WriteParams_T *p_writeParams);
Description
GATT Client initiates a write operation to GATT Server. This API should be used to write a Characteristic Value or Characteristic descriptor.
Refer ATT opcodes (ATT_WRITE_REQ/ATT_WRITE_CMD/ATT_PREPARE_WRITE_REQ/ATT_EXECUTE_WRITE_REQ) for write types.
Note
Write long attribute:
If the attribute is not long attribute, valueOffset should be set to 0 and writeType should be set to Write Request/Write Command as required.
If the attribute is a long attribute then first (ATT_MTU-3) bytes should be written with valueOffset set to 0 and writeType set to ATT_PREPARE_WRITE_REQ (See GATTC_WriteParams_T) in the API. The subsequent prepare write request should be called with appropriate value Offset and next set of data when event GATTC_EVT_WRITE_RESP is received. This should be repeated until expected number of bytes is queued up in the server. When event GATTC_EVT_WRITE_RESP is received for last prepare write request, this API should be called with writeType set to ATT_EXECUTE_WRITE_REQ and flags set to Execute write flag (See GATTC_WriteParams_T)
Events generated
GATTC_EVT_ERROR_RESP Generated when fail to write.
GATTC_EVT_WRITE_RESP Generated when write successfully.
ATT_EVT_TIMEOUT Generated when server does not respond the request.
Parameters
Parameter | Description |
---|---|
[in] connHandle | Handle of the connection to send write operation. |
[in] p_writeParams | Pointer to the Write Request parameters. Refer GATTC_WriteParams_T. |
Return values
Return value | Description |
---|---|
MBA_RES_SUCCESS | Successfully starts the write operation. |
MBA_RES_FAIL | Operation is not permitted. |
MBA_RES_OOM | Internal memory allocation failure. |
MBA_RES_INVALID_PARA | Invalid parameters. One of the following reasons: - Connection handle is not valid - Invalid write parameters. See GATTC_WriteParams_T for valid values. |
MBA_RES_NO_RESOURCE | No available resource to send write operation. |
MBA_RES_BUSY | GATT Client is busy. Another request is ongoing. |