7 Replies Latest reply on Aug 5, 2018 4:40 PM by HeGi_2497906

    BLE read only example


      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

        • 1. Re: BLE read only example



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





                          if(CYBLE_STATUS_STATUS_CHAR_HANDLE == read_request_param->attrHandle)






                              STATUS.attrHandle = 6;



                              STATUS.value.val = &Status;



                              STATUS.value.actualLen = 1;







          • 2. Re: BLE read only example

            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



            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?

            • 3. Re: BLE read only example

              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 ;






                          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");






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




              • 4. Re: BLE read only example

                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?

                • 5. Re: BLE read only example

                  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.

                  • 6. Re: BLE read only example

                    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?



                    #define STATUS_CHAR_DATA_LEN 1

                    uint8 BLE_Status = 0;

                    uint8 Status = 0;



                                    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;




                    • 7. Re: BLE read only example

                      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.