1 2 Previous Next 18 Replies Latest reply on Sep 14, 2017 11:10 AM by mholin_2439556

    PSOC 4 BLE as Central/Client to read data from CapSense Proximity Example

    mholin_2439556

      Hello All,

       

      Have one PSOC 4 BLE programmed with the Pioneer kit CapSense Proximity Example acting as the Peripheral/Server.  Want to set up another to be the corresponding Central/Client.  Started from the Pioneer kit IAS Central Example and changed the Find Me Profile to Custom then duplicated the custom CapSense service in the BLE component.  Got the two to connect, now need to code the client to enable notifications on the server.  Been pouring over examples and reading the API but still very confused as to which API  command to use and what the arguments specifically need to be.  Specifically how to specify the custom CapSense service CCCD and set it's value to 0x01 in the API function?

       

      Then how to actually read the notifications?

        • 1. Re: PSOC 4 BLE as Central/Client to read data from CapSense Proximity Example
          resh

                     

          For enabling notifications you have to write 0x01 to the CCCD of attributehandle of peripheral as shown below.

           

             data=0x01;

            writeReqParam.attrHandle=0x000F;//Att handle of CCCD

          writeReqParam.value.val=&data;

          CyBle_GattcWriteCharacteristicDescriptors(cyBle_connHandle, &writeReqParam);

          • 2. Re: PSOC 4 BLE as Central/Client to read data from CapSense Proximity Example
            e.pratt_1639216

            resh is correct;

            Some things to note:

            The CCCD value contains bits/flags for enabling/disabling notifications, indications, and possible some other configuration settings.

            The peripheral can technically still send notifications when this flag is disabled, but the software should be written to check this value and only send the value if enabled (for compliancy/interoperability when different clients connect to the peripheral).

            The notifications will occur as a BLE callback event CYBLE_EVT_GATTC_HANDLE_VALUE_NTF with the associated notification data object being pointed to by the eventParams

            • 3. Re: PSOC 4 BLE as Central/Client to read data from CapSense Proximity Example
              mholin_2439556

              Hi guys, thank you so much, just what I needed something clear and concise.  However not terribly strong with C++ and got a few errors:

               

              Added uint8 for the first line:  uint8 data=0x01;

               

              Then added:  extern CYBLE_GATTC_WRITE_REQ_T * writeReqParam;

              Before main() but still not right because still getting “->” error for the next two lines:

               

                          writeReqParam.attrHandle=0x000F;  //Att handle of CCCD

                          writeReqParam.value.val=&data;

               

              and a “!” warning for the last line:

               

                   CyBle_GattcWriteCharacteristicDescriptors(cyBle_connHandle, &writeReqParam);

               

              Am sure I have something wrong with the syntax.

               

              Thanks,

              Mark

               

              Sent from Mail for Windows 10

              • 4. Re: PSOC 4 BLE as Central/Client to read data from CapSense Proximity Example
                e.pratt_1639216

                Change the line:

                extern CYBLE_GATTC_WRITE_REQ_T * writeReqParam;

                to

                extern CYBLE_GATTC_WRITE_REQ_T writeReqParam;

                 

                extern means that you have the line:

                CYBLE_GATTC_WRITE_REQ_T writeReqParam;

                (the declaration) in a different file that you want to use/refer to, and the compiler should assume it is there until you compile the program.

                The asterisk (*) means that writeReqParam is a pointer, BUT when you pass the variable as &writeReqParam to the function call, you are passing a pointer of that variable. This means that you are passing a pointer to a pointer to an extern declared variable called writeReqParam (which is not what the function wants passed to it). Therefore, make sure you have the declaration without the asterisk, otherwise you are passing the function a pointer to a pointer when it wants a pointer to a variable (the CYBLE_GATTC_WRITE_REQ_T var to be precise).

                • 5. Re: PSOC 4 BLE as Central/Client to read data from CapSense Proximity Example
                  mholin_2439556

                  That is great, thank you so much.  You pointed me in the right direction for reading the notification, can I just bounce that off you?

                   

                  I put this before main():

                   

                  /* 'proximityValue' stores the proximity value read from CapSense component */

                  uint8 proximityValue;

                   

                  // to read notifications

                  CYBLE_GATTC_HANDLE_VALUE_NTF_PARAM_T * eventParam;

                   

                  Then this in main() to actually read the value:

                   

                  //CYBLE_EVT_GATTC_HANDLE_VALUE_NTF

                  CYBLE_GATTC_HANDLE_VALUE_NTF_PARAM_T *DataNotification=(CYBLE_GATTC_HANDLE_VALUE_NTF_PARAM_T *)eventParam;

                  proximityValue= *DataNotification->handleValPair.value.val;

                   

                  It compiles without error but that probably doesn’t mean much, lol.

                   

                  Thanks again.

                  Mark O.

                   

                   

                   

                  Sent from Mail for Windows 10

                  • 6. Re: PSOC 4 BLE as Central/Client to read data from CapSense Proximity Example
                    mholin_2439556

                    Before getting to reading the data, afraid I am still stuck on enabling notifications.  I get this error back from the call to :

                     

                    apiResult=CyBle_GattcWriteCharacteristicDescriptors(cyBle_connHandle, &writeReqParam);

                     

                    CYBLE_ERROR_INVALID_PARAMETER  'connHandle' value does not represent any existing entry in the Stack 

                     

                    Sent from Mail for Windows 10

                    • 7. Re: PSOC 4 BLE as Central/Client to read data from CapSense Proximity Example
                      e.pratt_1639216

                      The connHandle refers to writing the notification settings to the peripheral from the client; This requires you to be connected with bluetooth to the device. If you are trying to call that function without being connected to the peripheral, then it will throw the error you are seeing.

                      Connect to the peripheral over bluetooth first, then call the writecharacteristicdescriptors to set the notification settings.

                      • 8. Re: PSOC 4 BLE as Central/Client to read data from CapSense Proximity Example
                        e.pratt_1639216

                        To read the value, you will want to do:

                        proximityvalue = Datanotification->handleValPair.value.val;

                        The asterisk in the front is unecessary, as in c++ that will dereference a pointer. But, the -> will dereference a pointer while accessing a value from the object pointed to (basically doing both steps at the same time). This means that you would be looking at the object pointed to by the pointer which is pointed to by the DataNotification pointer.

                        In C++, *PointerValue.ValueAccess is equivalent to PointerValue->ValueAccess just with slightly different syntax (and possible slightly different compilation/execution, but essentially the same affect).

                        • 9. Re: PSOC 4 BLE as Central/Client to read data from CapSense Proximity Example
                          mholin_2439556

                          I had assumed establishing a connection would be a prerequisite to passing parameters and data between two BLE devices.  The blue status LED on the PSoC_4_BLE_Central_IAS Pioneer board goes from flashing to solid while the status LED on the PSoC_4_BLE_CapSense_Proximity module (powered separately) goes from flashing to off which according to both sets of documentation indicates both are connected.   As a test I reset (button) the PSoC_4_BLE_CapSense_Proximity module after they were connected and observed the blue LED on the PSoC_4_BLE_Central_IAS Pioneer board go out.

                           

                          Also tried both connHandle and cyBle_connHandle in the function argument with the same results.

                           

                          Really appreciate your help and patience.  Will continue to investigate.

                           

                           

                          Sent from Mail for Windows 10

                          • 10. Re: PSOC 4 BLE as Central/Client to read data from CapSense Proximity Example
                            e.pratt_1639216

                            Have you discovered the services/characteristics on the device yet? It could be it wants you to discover first? (This shouldn't be a requirement in theory)

                            cyBle_connHandle should be initialized to the correct value after the CYBLE_EVT_GATT_CONNECT_IND event occurs.

                            Possibly try settings a small timer after connection to see if you are just attempting it too soon? There could be a different event for the BLE connection process that needs to finish before setting the notification enabled.

                            • 11. Re: PSOC 4 BLE as Central/Client to read data from CapSense Proximity Example
                              mholin_2439556

                              I am working from the PSoC_4_BLE_Central_IAS example and it does look like it does a discovery.  I moved where I am trying to enable notifications to after the discovery call function.  Also set a timer before where I originally had the call.  Does it matter where the call to these API functions go?  I am putting them in main.c should they go in the ApplicationEventHandler() instead?

                               

                              Sent from Mail for Windows 10

                              • 12. Re: PSOC 4 BLE as Central/Client to read data from CapSense Proximity Example
                                e.pratt_1639216

                                You should be able to call the BLE functions from main.c perfectly fine.

                                Just to be clear: You are trying to send a notification from the peripheral to the client device using the notification function, but you want the client to send an enable-notification value to the CCCD on the peripheral first.

                                Since you are using the PSoC_4_BLE_Central_IAS, why not wait until the flag deviceConnected becomes true before sending the notification enable write characteristic request?

                                Create a flag for "notifications not enabled", then set it to true after you attempt to write the notifications, and just call the notification characteristic write in main based on the flag being true. Ex:

                                if(notificationsNotEnabled)

                                {

                                  SendNotification(); //send the notification characteristic/enable value to the remote device

                                  notificationsNotEnabled = false; //set this to true when you receive the device connected event or after discovery is complete and notifications are not enabled? Or, put this entire check inside of the if(deviceConnected){} if statement.

                                }

                                Perhaps, try creating a custom central device from barebones and set it up to enable the notifications/write the value on connection? That way you can verify it is not something with the way you are calling the API, but rather something with the way the application overall is behaving for the IAS example you are using.

                                • 13. Re: PSOC 4 BLE as Central/Client to read data from CapSense Proximity Example
                                  mholin_2439556

                                  Just to be clear: You are trying to send a notification from the peripheral to the client device using the notification function, but you want the client to send an enable-notification value to the CCCD on the peripheral first.

                                  Yes, but only because that was my understanding of the handshake between client and server.  If I can enable notifications directly at the server side that would work as well.  I just need the server to stream data.

                                  Since you are using the PSoC_4_BLE_Central_IAS, why not wait until the flag deviceConnected becomes true before sending the notification enable write characteristic request?

                                  Precisely.  I was doing at the end of:

                                  if(peripheralFound)

                                  {

                                  Connect to pheripheral.

                                  /* Reset flag to prevent resending the Connect command */

                                                 peripheralFound = FALSE;

                                  I put the enable notifications here.

                                  }

                                  Because I thought that would be after the devices had connected and I could use the peripheralFound flag to act as you suggest.

                                  But I also tried it in:

                                  if(deviceConnected)

                                  {

                                  In here.

                                  }

                                  As you suggested insure the connection had been made.  But I still got that error.  It was being called continuously there though because I had not implemented the flag as you suggest.  I agree that would probably be the better place for it.  I will move it back to here and add the flag as that seems cleaner.

                                  Right now I am trying to verify that the connHandle has the correct value. 

                                   

                                   

                                   

                                  Sent from Mail for Windows 10

                                  • 14. Re: PSOC 4 BLE as Central/Client to read data from CapSense Proximity Example
                                    e.pratt_1639216

                                    If you can watch the connHandle value in real time with a debugger, that would be useful to see;

                                    You should be able to set the default value for the notification enable under the BLE component at the TopDesign.cysch page:

                                     

                                    NotificationEnablePicture.PNG

                                    Hmm, I just realized that my own code is using the value cyBle_connHandle.bdHandle for the reference to the device when calling the BLE apis. Try looking at the connHandle data structure and see if you need to pass the connHandle.bdHandle member rather than the connHandle data structure.

                                    1 2 Previous Next