You are here

Write custom characteristic value. | Cypress Semiconductor

Write custom characteristic value.

Summary: 1 Reply, Latest post by Fabrizio Restori on 11 Aug 2016 02:16 PM PDT
Verified Answers: 0
Last post
Log in to post new comments.
rfc_1549836's picture
25 posts

On a peripheral / server BLE, I acquire a value from one sensor and I want to store this value on a custom characteristic.
The CyBle_GattsWriteAttributeValue seem to be a good function  and it need a connection handler as parameter, but I want to store the value even if no one (Central / Client) is connected to BLE peripheral.
Is possible, or attribute value can be updated only when connected ? how to do?

Thanks, Fabrizio


rfc_1549836's picture
25 posts

Ok, I've solved by myself.
Here my solution: I hope it will be useful for someone.
It was not easy, because the documentation is unclear,  there are poor explained examples and I'm new on BLE development.
Anyway, I wrote a simple function for my Custom Characteristic value.
I'm using a float32 (4 bytes long) for Custom Chacteristic, so the function need to be modified as needed.


void SetmyCustomAttributeValue ( float32 valore, uint16 handler)
    CYBLE_GATT_ERR_CODE_T apiGattErrCode = 0;

    CYBLE_GATT_HANDLE_VALUE_PAIR_T    handleValuePair;
    handleValuePair.value.val = (uint8 *)&valore;
    handleValuePair.value.len = sizeof(valore);
    handleValuePair.attrHandle = handler;
    /* To register the service change in the Database of the GATT Server */
    apiGattErrCode = CyBle_GattsWriteAttributeValue(&handleValuePair, 0u, NULL,CYBLE_GATT_DB_LOCALLY_INITIATED);
    if (apiGattErrCode != 0)
        DBG_PRINTF ("Service Changed Attribute DB write failed\r\n");
        DBG_PRINTF ("Service Changed Attribute DB write success\r\n\n");

The CyBle_GattsWriteAttributeValue() function is called with NULL as connection handler, this because I want to initialize my attribute value even without any connection.
Because I'm operating in a local GATT DB (from the server side, not from remote client) the parameter CYBLE_GATT_DB_LOCALLY_INITIATED was used as 4th value.
Pay attention to the right initalization of  CYBLE_GATT_HANDLE_VALUE_PAIR_T structure.


Log in to post new comments.