- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
Solved! Go to Solution.
- Labels:
-
BLE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What is the attribute handle of the characteristic.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you lipens26. You have made it a very pleasant afternoon indeed. Thank you too other responders.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.