11 Replies Latest reply on Apr 6, 2019 11:41 PM by PY_21

    read value from multiple custom characteristics

    adhuc_3921366

      hi,

       

      i have been look at this for some while now and i will openly admit i am very new to BLE and cypress/ Psoc4.

       

      i have used the example programs to create a peripheral and central devices. i have 2 custom services which i have added to both the peripheral and central device.

       

      i have enabled notifications for both of these and this is where the issue begins.

       

      when i receive data from one or both of the custom services i get the data in both.

       

      i am basically duplicating the code from the example where the capsense was read.

      which i believe was in case CYBLE_EVT_GATTC_HANDLE_VALUE_NTF:

       

      so i have the two lines below (one for pressure and one for temperature)

      CYBLE_GATTC_HANDLE_VALUE_NTF_PARAM_T *TempNTF;

      CYBLE_GATTC_HANDLE_VALUE_NTF_PARAM_T *PressNTF;

       

      i then have the lines

      PressNTF = (CYBLE_GATTC_HANDLE_VALUE_NTF_PARAM_T *)eventParam;

      TempNTF = (CYBLE_GATTC_HANDLE_VALUE_NTF_PARAM_T *)eventParam;

       

      any help or code i can use would be much appreciated.

       

      thanks

       

      adam

        • 1. Re: read value from multiple custom characteristics
          PY_21

          Hello Adam,

           

          Please refer to the Day020_BLE_UART project in the GitHub for more information on handling notifications in BLE central and peripheral.

           

          Thanks,

          P Yugandhar.

          • 2. Re: read value from multiple custom characteristics
            adhuc_3921366

            Hi P Yugandhar,

             

            thank you for your response, however pointing me at the example projects does not help, i have had this multiple times from this site and it is putting me off using cypress devices in future.

             

            a little discussion would be more useful! to top it off pointing me in the direction of a example program that has very little comments does not help someone whom has stated he is new to your libraries.

             

            PS a correct answer to your does not mean a correct answer to me!   

            • 3. Re: read value from multiple custom characteristics
              PY_21

              Hello Adam,

               

              In the CYBLE_EVT_GATTC_HANDLE_VALUE_NTF event, the parameter CYBLE_GATTC_HANDLE_VALUE_NTF_PARAM_T will give information on from which handle we are getting the data from peripheral device. This contains the Handle value pair(attribute handle, value, length). Please refer to the event parameter structure in BLE component datasheet for more information.
              At the central device, we have to check for the required attribute handle( whether from temperature characteristic or pressure characteristic)as shown in below code and then read the values.
              In the peripheral device all custom services and thier characteristics have different attribute handle values. Please check for different attribute handles in BLE_custom.h file of peripheral project. We have to check with theses attribute handles in the central device.

               

              Question: I have the two lines below (one for pressure and one for temperature)
              CYBLE_GATTC_HANDLE_VALUE_NTF_PARAM_T *TempNTF;
              CYBLE_GATTC_HANDLE_VALUE_NTF_PARAM_T *PressNTF;
              Ans: We can define one event parameter. This event parameter will contains the data of particular custom characteristic handle and will be updated for every notification.

               


              **********************************************
              case CYBLE_EVT_GATTC_HANDLE_VALUE_NTF:


              CYBLE_GATTC_HANDLE_VALUE_NTF_PARAM_T *Notification;
              if(Notification->handleValPair.attrHandle ==(0x000Eu))
              {
              temperature=Notification->handleValPair.value.val[0];
              }
              else if(Notification->handleValPair.attrHandle ==(0x0010u))
              {
              pressure=Notification->handleValPair.value.val[0];
              }
              **********************************************

               

              Please let me know if you have any questions.

               

               

              Thanks,

              P Yugandhar.

              1 of 1 people found this helpful
              • 4. Re: read value from multiple custom characteristics
                adhuc_3921366

                Hi P yugandhar,

                 

                thank you for your advice above, i have now managed to split out the data as required.

                 

                i have another question, based on the day 20 uart ble example program...

                 

                i have used this as my base for my current code and have managed to communicate to one BLE peripheral, read then split out the data.

                 

                my next step will be to disconnect from this BLE device and connect to another peripheral read the data then disconnect again.

                 

                i have duplicated the UUID service and attribute code at the top with my new UUID and attributes, and added in the corresponding cyble_gattcdiscoverprimaryservicebyuuid() however it does not seem to do anything here, it just loops round unlike the original device which connects, even after the altered code.

                 

                if i plug in my original device it connects and discovers fine, but when i plug in the new peripheral it will not discover.

                 

                i have tried looking in debug for a reason and i have come up short.

                 

                is there any advice you can give to move me forward?

                 

                thanks

                 

                adam

                • 5. Re: read value from multiple custom characteristics
                  PY_21

                  Hello Adam,

                   

                  Can you please share your project so that we can check and see what is actually causing the problem.

                   

                  Thanks,

                  P Yugandhar.

                  • 6. Re: read value from multiple custom characteristics
                    adhuc_3921366

                    Hi P Yugandhar,

                     

                    please see attached projects, there are two peripherals toilet and fresh water. The plan is to connect to fresh water, disconnect and connect to toilet. at the moment i am plugging fresh water in, reading the values, unplugging fresh water, plugging toilet in, however i am unable to discover the services with the toilet node.

                     

                    thank you in advance for your assistance.

                     

                    adam

                     

                    • 7. Re: read value from multiple custom characteristics
                      PY_21

                      Hello Adam,

                       

                      Please refer to the attached modified project where I'm able to discover the services. Please make sure that the UUID values in the peripheral BLE component and the values which we define in the central device should be same.

                      Please let me know if you have any questions.

                       

                      Thanks,

                      P Yugandhar.

                      • 8. Re: read value from multiple custom characteristics
                        adhuc_3921366

                        Hi P Yugandhar,

                         

                        thank you for your time it is much appreciated, i have not tested the code above but i will over the next few days. I feel like i might have missed something silly with the code. i was sure i had the right UUId set. once i have this bit sorted i am going to try and implement the connection and disconnection of the devices in a round robin system. i am going to use Day 30 time multiplexed central as my base. unless there is another example that would be more suited ?

                         

                        thanks

                         

                        adam 

                        • 9. Re: read value from multiple custom characteristics
                          PY_21

                          Hello Adam,

                           

                          You can also refer the Day_024_Throughput example project(GATT_Notification_Data_incoming and GATT_Notification_Data_outgoing) in the GitHub which demonstrates maximum data transfer in a BLE communication from a device.

                           

                          Thanks,

                          P Yugandhar.

                          • 10. Re: read value from multiple custom characteristics
                            adhuc_3921366

                            Hi P Yugandhar,

                             

                            thank you for all of your help so far, however i am in need of it again please.

                             

                            i think i have possibly made a small mistake but i am unable to find it.

                             

                            i have now got 4 remote sensor nodes all connecting to the central node.

                             

                            they all discover the handles on each remote node, however i am getting a random scenario where sometimes i seem to only get one notification set on each remote node, then other times it enables both.

                             

                            below is the tera term print of what i get in and the order, it is identical whether one or both notifications are enabled.

                             

                            CYBLE_EVT_GATTC_FIND_BY_TYPE_VALUE_RSP

                            CYBLE_EVT_GATTC_READ_BY_TYPE_RSP

                            CYBLE_EVT_GATTC_READ_BY_TYPE_RSP

                            CYBLE_EVT_GATTC_FIND_INFO_RSP

                            Flush handle found

                            CYBLE_EVT_GATTC_FIND_INFO_RSP

                            CYBLE_EVT_GATTC_FIND_INFO_RSP

                            Waste handle found

                            CYBLE_EVT_GATTC_XCHNG_MTU_RSP

                            CYBLE_EVT_GATTC_WRITE_RSP

                            CYBLE_EVT_GATTC_HANDLE_VALUE_NTF

                            • 11. Re: read value from multiple custom characteristics
                              PY_21

                              Hello Adam,

                               

                              Please make sure that CyBle_ProcessEvents is called at regular intervals in the firmware. Please go through the API description in BLE Component configuration for the time interval at which CyBle_ProcessEvents must be called. If a custom function consumes more time for execution, call CyBle_ProcessEvents inside it.

                               

                              Thanks,

                              P Yugandhar.