BLE read only example

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

cross mob
HeGi_2497906
Level 5
Level 5
100 replies posted 50 replies posted 25 replies posted

Could I get a real clear example of how to do read only BLE call, I have read through 10 app notes and my code does not function.

My code is at the end of this tread.

Re: CYBLE_EVT_GATTS_READ_REQ - Identify which characteristic was read

0 Likes
1 Solution

Gyan, I think I understand now, to read, the update to the GATT database must be done outside the event handler, a write must be done inside the event handler?  I think this is the answer that escaped me, if I am correct.

I can now read my values correctly, thank you.

Herb

View solution in original post

0 Likes
7 Replies
Anonymous
Not applicable

Hello,

I think you need to make the modification to point to the characteristic handle as below, point to the attribute handle

case CYBLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ:

                if(CYBLE_STATUS_STATUS_CHAR_HANDLE == read_request_param->attrHandle)

                {

                    STATUS.attrHandle = 6;

                    STATUS.value.val = &Status;

                    STATUS.value.actualLen = 1;

                }

        break;

0 Likes

I thank you for your effort, but this seems inconsistent with the documentation.  The structure for the event has no value or length field.  Here is my attempt to use this.  Also you have to assign the event a param and define the status.

CYBLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ Event parameter type is

CYBLE_GATTS_CHAR_VAL_READ_REQ_T.

struct CYBLE_GATTS_CHAR_VAL_READ_REQ_T

Data Fields

• CYBLE_CONN_HANDLE_T connHandle

• CYBLE_GATT_DB_ATTR_HANDLE_T attrHandle

• CYBLE_GATT_ERR_CODE_T gattErrorCode

Why is there not a simple read only command, like the write?

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

CYBLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ event is generated every time a client reads data from the server.

Using the event parameters you can identify the attribute handle for which the Read was requested from the Client.

For example in the below case the attribute handle is checked if it is for RGB data and correspondingly a message is printed.

CYBLE_GATTS_CHAR_VAL_READ_REQ_T rdresponse ;

.

.

.

case CYBLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ:

            rdresponse = *( CYBLE_GATTS_CHAR_VAL_READ_REQ_T  * ) eventParam;

            if( rdresponse.attrHandle ==  CYBLE_RGB_LED_SERVICE_RGB_LED_CHARACTERISTIC_CHAR_HANDLE )

            {

                UART_UartPutString("Read RGB data\n");

            }

            break;

Can you please let us know what are you trying to accomplish in more detail, so that we can help you.

Thanks,

Ranjith

0 Likes

I am sorry if I was not clear.  What I am trying to do is have the app read data in the gatt data base, as an example the battery value, he reads it on start up, and if the status word indicates a battery issue.  Otherwise the embedded program just tracks it and updates the value, there is no need for a notification.

So want I want is an example of the app do a read only of a value the embedded program updates continuously.

In your example is seems the read is activating a function, but how does that event pass the data back to the app?

0 Likes
Anonymous
Not applicable

A read request from the client to server is handled by Stack. There is no need for anything to be done from the server side in the application.

The above event is generated on server side so that you can track if a read request was sent by client.

0 Likes

I have been reading through the files you sent, thank you.

If I am understanding correctly, the way to read data is to set up a service and write to it like this, with this the app service for STATUS would read back the value in Status.  Even when Status is known to have a good value, the app reads back a zero, if I enable write, and write to it, it writes and reads only the value the app sends, the embedded program data is not making it through?

CYBLE_GATT_HANDLE_VALUE_PAIR_T STATUS;

#define STATUS_CHAR_DATA_LEN 1

uint8 BLE_Status = 0;

uint8 Status = 0;

                /*STATUS*/

                if(CYBLE_STATUS_STATUS_VALUE_CHAR_HANDLE == write_request_param->handleValPair.attrHandle)

                {

                    //BLE_Status = write_request_param->handleValPair.value.val[0];

                    BLE_Status = Status;

                    STATUS.attrHandle = CYBLE_STATUS_STATUS_VALUE_CHAR_HANDLE;

                STATUS.value.val = &BLE_Status;

                STATUS.value.len = STATUS_CHAR_DATA_LEN;

                CyBle_GattsWriteAttributeValue(&STATUS,FALSE,&connHandle,FALSE);

                }

pastedImage_0.png

0 Likes

Gyan, I think I understand now, to read, the update to the GATT database must be done outside the event handler, a write must be done inside the event handler?  I think this is the answer that escaped me, if I am correct.

I can now read my values correctly, thank you.

Herb

0 Likes