cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

Anonymous
Not applicable

Can someone explain how to use CyBle_GattsReadAttributeValue()?

   

Or I have to use something else if I want GATT sever device to read a characteristic value from its GATT database?

0 Likes
Reply
1 Solution
Anonymous
Not applicable

Try this:

   

CYBLE_GATT_HANDLE_VALUE_PAIR_T       myHandle;

   

    myHandle.attrHandle = attrHandle; /* Attribute Handle of the characteristic in GATT Database*/
    myHandle.value.val = dataArray; /*Array where you want to store the data*/
    myHandle.value.len = len; /* Length of data*/
    
    CyBle_GattsReadAttributeValue(&myHandle, &cyBle_connHandle, CYBLE_GATT_DB_LOCALLY_INITIATED);

View solution in original post

0 Likes
Reply
10 Replies
Honored Contributor II

On a GATT server your code just writes the value of an attribute. The BLE stacks then takes care of the rest (providing the value to GATT clients upon request). There is no need to read a value from the GATT server since your code already knows the current value.

0 Likes
Reply
Anonymous
Not applicable
        Ok, so how do I acces the value of characteristics?   
0 Likes
Reply
Anonymous
Not applicable

Try this:

   

CYBLE_GATT_HANDLE_VALUE_PAIR_T       myHandle;

   

    myHandle.attrHandle = attrHandle; /* Attribute Handle of the characteristic in GATT Database*/
    myHandle.value.val = dataArray; /*Array where you want to store the data*/
    myHandle.value.len = len; /* Length of data*/
    
    CyBle_GattsReadAttributeValue(&myHandle, &cyBle_connHandle, CYBLE_GATT_DB_LOCALLY_INITIATED);

View solution in original post

0 Likes
Reply
Anonymous
Not applicable

Thank, you! worked like a charm!

   

I had done everything the same except i didn't use this line - 

   

myHandle.value.val = dataArray; /*Array where you want to store the data*/

   

because i thought that it should be left blank as i were not writing anything. without giving the array to write data in, the read function just sent me to no return and went in a loop. But this fixed it.

0 Likes
Reply
Anonymous
Not applicable

What is the attribute handle of the characteristic.

   

 

   

-Thanks

0 Likes
Reply
Anonymous
Not applicable
        Find the header for the service you're using. If you made your own custom service then there is gonna be something like custom.h. Then in the header file there will be some lines with attribute handles for all the stuff you gave names for while creating the custom service. There will be a long string I believe it was highlighted Green and that is the attribute handle that you need to use every time when you want to tell which characteristic or other fields you want to read or write. I hope this helps at least a little bit. It has been a year since I last worked with the PSoC.   
0 Likes
Reply
New Contributor II

Referring to the code above, if I want to populate and continually update the value field of a custom characteristic of a custom service with say an ADC reading, how do I associate the myHandle structure with my custom characteristic in the GATT database?

0 Likes
Reply
Anonymous
Not applicable
        Well if I understand your question right you associate with specific characteristic with this line myHandle.AttrHandle=(insert a handle generated for your characteristics, you can find it in custom.h) MyHAndle.value.val=(address of the variable containing ADC reading) And then use write function   
0 Likes
Reply
New Contributor II

Thank you lipens26.  You have made it a very pleasant afternoon indeed.  Thank you too other responders.

0 Likes
Reply
Anonymous
Not applicable

Pat,

   

You need to call 'CyBle_GattsWriteAttributeValue' to update the GATT database with your own data. The handle and its structure remains the same as described above, except the dataArray now contains the new data from your ADC and length is equal to data length of the array.