2 Replies Latest reply on Jul 21, 2015 4:28 PM by elias.hernndez

    Notifications not received

    elias.hernndez

      I'm making a simple project with a custom characteristic (with read, write and notify properties enabled) where I can modify a uint8 value.

         

      With CySmart I can connect to the psoc, and read and write the characteristic value, so everything seems fine.

         

      To test notifications, I added a button that when pushed it triggers an interruption, in which i write to the GATT database to modify the characteristic value. So when notifications are enabled, i should see a real time value change in the characteristic when I press the button.

         

      The problem is that when i activate notifications by writing to the CCCD and then i press the button, the characteristic value doesn't change in real time, but if then i read the characteristic value, it's correctly updated, so the button interruption works and updates the characteristic value, but the notification code doesn't notify me the changes.

         

      I submitted the code as an attachment

        • 1. Re: Notifications not received
          rohit.kumar

          I see an issue.

             

          Under your 'CYBLE_EVT_GATTS_WRITE_REQ' event in 'BluetoothEventHandler', you are reading the value of CCCD in 'startNotification' but writing the value 'characteristic_data' to it using 'CyBle_GattsWriteAttributeValue'.

             

          I have not see your BLE services and characteristics, but I assume you have a Characteristic 'Cyble_test_control -> Test_char' used to do read, write and notify. As you support Notification, you also have a CCCD (attribute handle == CYBLE_TEST_CONTROL_TEST_CLIENT_CHARACTERISTIC_CONFIGURATION_DESC_HANDLE) that is used to detect if client has enabled Notification or not.

             

          So you need to handle to Write requests under event 'CYBLE_EVT_GATTS_WRITE_REQ', depending on the attribute handle to which the request has been initiated to:

             

          1) (wrReqParam->handleValPair.attrHandle == CYBLE_TEST_CONTROL_TEST_CLIENT_CHARACTERISTIC_CONFIGURATION_DESC_HANDLE), which you are currently handling

             

          2) (wrReqParam->handleValPair.attrHandle == CYBLE_TEST_CONTROL_TEST_CHAR_HANDLE), which is not there, atleast correctly. When you get a write request on this attribute handle, then go ahead and use 

             

          characteristic_data[0] = wrReqParam->handleValPair.value.val[0];                
                          CYBLE_GATT_HANDLE_VALUE_PAIR_T data_to_be_written;
                          data_to_be_written.attrHandle = CYBLE_TEST_CONTROL_TEST_CHAR_HANDLE;
                          data_to_be_written.value.val = characteristic_data;
                          data_to_be_written.value.len = sizeof(characteristic_data);
                          CyBle_GattsWriteAttributeValue(&data_to_be_written, 0, &cyBle_connHandle, CYBLE_GATT_DB_LOCALLY_INITIATED);

             

           

             

          But if you have to update the CCCD attribute value, then you need

             

                          CYBLE_GATT_HANDLE_VALUE_PAIR_T data_to_be_written;
                          data_to_be_written.attrHandle = CYBLE_TEST_CONTROL_TEST_CLIENT_CHARACTERISTIC_CONFIGURATION_DESC_HANDLE;
                          data_to_be_written.value.val = startNotification;
                          data_to_be_written.value.len = sizeof(startNotification);
                          CyBle_GattsWriteAttributeValue(&data_to_be_written, 0, &cyBle_connHandle, CYBLE_GATT_DB_LOCALLY_INITIATED);

             

           

             

          I see that your notification code in main.c is correct.

             

           

             

          Refer to AN91162 (http://www.cypress.com/documentation/application-notes/an91162-creating-ble-custom-profile?source=search&keywords=AN91162), if you have not yet, to understand how to handle these custom events.

          • 2. Re: Notifications not received
            elias.hernndez

            Thanks for answering roit, but I still can't get it work.

               

            I've been testing with a modified version of the code, but still get the same result. As far as I see, the problem is that when i try to enable notifications by writing in the CCCD, the GATT database is correctly updated, but the startNotification variable is "locally" modified, instead of globally modified, so when the button interruption is triggered, the psoc never enters in the notification part because the startNotification variable hasn't changed its value from 0.

               

            Except that thing, all the code works fine, because i modified the code to avoid the startNotification verification (thus we ever enter in the notification code) and it notifies correctly and in real time the button interruption.

               

            Thus the problem is set to globally update the startNotification variable in any part of the code, so any function can access to the updated value of the variable.

               

            This time i attach my updated version of the code, and a screenshot of my custom service and characteristic.