How to read attribute values from remote device?

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

cross mob
jamec_2673086
Level 3
Level 3
5 likes given First like received First like given

Hello,

I am novice to BLE Development.In my project i want to perform read & write operation between CY8CKIT048-PSOC 4 board and android app.

In that i have successfully performed write operation using custom profile->custom Service & characteristic.

Now i am stuck for READ operation from android app.

I want to know whole cycle of operations performed when i click on READ in my android app,which event will be occurred in event handler & with the help of which function i can read attribute values to android app.

0 Likes
5 Replies
Anonymous
Not applicable

There may be orthogonal events like authentication requests, MTU exchange requests, etc. that can occurr, but generally

You need to make sure that your characteristic is allowed for reading based on the configuration settings of authentication, encryption, etc.

Afaik, you shouldn't need to explicitly handle the read request from the android phone in your callback if you have it setup properly. The DB on the BLE peripheral device should be sending the value upon request if allowed. Can you tell us what you have tried? Or what issues you are running into specifically?

jamec_2673086
Level 3
Level 3
5 likes given First like received First like given

Hi pratt,

While looking for above issue i get some solutions but they(solutions) come with some more queries.

CYBLE_EVT_GATTS_WRITE_REQ event is responsible for writing data from ble client to ble server.

CyBle_GattsWriteAttributeValue() with this function we can write attribute value to server database what ever we got from client.

Now,BLE comonent Datasheet says that

CYBLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ event will be called when client initiates read request.

CyBle_GattsReadAttributeValue() will be used to read attribute value from database.

But,

I am able to READ attribute value from server database without above mentioned event as well as CyBle_GattsReadAttributeValue().

Please correct me if there is any misunderstanding with me.

0 Likes
Anonymous
Not applicable

1. yes, the CYBLE_EVT_GATTS_WRITE_REQ event is what you handle for writing values received from the Client onto the Server GATT DB.

2. CYBLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ only occurs when the characteristic:

/** Event parameter type is CYBLE_GATTS_CHAR_VAL_READ_REQ_T. It is triggered on server side

       when client sends read request and when characteristic has CYBLE_GATT_DB_ATTR_CHAR_VAL_RD_EVENT

       property set. This event could be ignored by application unless it need to response by error response which

       needs to be set in gattErrorCode field of event parameter. */

Thus, you only need to handle the read event if you set the characteristic to require permissions of authentication or encryption for the client to access it.

So you got one of the two correct

Epratt

Hi Pratt,

Ya I got correct solution for my problem But sometimes solution comes with new doubts.

Here ,Is CYBLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ event necessary condition to make Read request & read value from server by client(CySmart app) ?

And can we dynamically allocate memory in cypress ?

If yes then How bcoz i did not find any dynamically allocation function(malloc,calloc,realloc & New) in cypres creator ?

0 Likes
Anonymous
Not applicable

Hello Jagir,

Here Is CYBLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ event necessary condition to make Read request & read value from server by client(CySmart app) ?

It is only used/necessary if you specifically set a setting to be protected for encryption or authentication. Using the CySmart application. If you are worried about security or privacy, then you will probably want to handle it. Otherwise, no. You don't need to handle it by default as the default setting is to allow any reads without encryption/authentication.

And can we dynamically allocate memory in cypress ?

If yes then How bcoz i did not find any dynamically allocation function(malloc,calloc,realloc & New) in cypres creator ?

You CANNOT dynamically allocate memory. The compiler compiles memory statically. The only things that are "dynamic" are the stack function calls, and the heap associated with the passed parameters.

The benefits of malloc,calloc,realloc, and new are not really appreciable at such a small code space/level. So, unless you are writing code for a large chip (MB+) then generally the application will be too small to save space or complexity by using dynamic memory allocation.

You can still do scoping however, which will allow reuse of memory within different functions.

0 Likes