3 Replies Latest reply on Nov 11, 2019 11:53 AM by NazarP_56

    Writting local to send an indication

    DaGa_4352226

      Hello Community

       

      I am working with a  PSoC 6 BLE Prototyping Kit (CY8CPROTO063-BLE). With it I am saving some information in the EEPROM and after the user wants the values, writes  on the appropiate CCCD to send indication or indicatons  to the client, but first it saves the info in the local.

       

      The problem that chip is sending is the following:

      • Error with wrtting in the local database 13 //  CY_BLE_GATT_ERR_INVALID_ATTRIBUTE_LEN
      • Error to write in the Indications to stop 1 // CY_BLE_GATT_ERR_INVALID_HANDLE

      On the first error, I have been doing the same on the other cases that I need to write first local and I did not have any problems before. On the Second, Im writting to the CCCD to stop the indications and the chip is sending me an error of invalid ATT Handle.

       

      Any Clue?

      Regards,

      David Caraveo

       

      Here is a snapchat of my code:

       

      void SendLastReport(cy_stc_ble_conn_handle_t connHandle)

      {

          uint8_t reportData[GENERAL_REPORT_SIZE]; //47

          cy_en_em_eeprom_status_t eepromReturnValue = Em_EEPROM_Read(EEPROM_GENERAL_REPORT_START + ((controlNumber[0]-1)*GENERAL_REPORT_SIZE), reportData, sizeof(reportArray));

          if (eepromReturnValue == CY_EM_EEPROM_SUCCESS)

          {

              cy_stc_ble_gatt_value_t value = {

                  .actualLen = 0,

                  .len = GENERAL_REPORT_SIZE, //47 bytes

                  .val = reportData};

              cy_stc_ble_gatt_handle_value_pair_t attibuteInfo = {

                  .value = value,

                  .attrHandle = CY_BLE_REPORT_LAST_GENERAL_REPORT_CHAR_HANDLE};

              cy_en_ble_gatt_err_code_t errorLocal = Cy_BLE_GATTS_WriteAttributeValueLocal(&attibuteInfo);

              if (errorLocal == CY_BLE_GATT_ERR_NONE)

              {

                  cy_en_ble_api_result_t errorIndication = Cy_BLE_GATTS_SendIndication(&connHandle,&attibuteInfo);

                  if (errorIndication == CY_BLE_SUCCESS)

                      DBG_PRINTF("Indidcation send\r\n");

                  else

                      DBG_PRINTF("Error with the indication %d\r\n" , errorIndication);

              }

              else

                  DBG_PRINTF("Error with wrtting in the local database %d\r\n" , errorLocal);

          }

          else

          {

              DBG_PRINTF("Error to read EEPROM %d\r\n" , eepromReturnValue);

          }

          uint8_t clearIndication [2] = {0x00,0x00};

          cy_stc_ble_gatt_handle_value_pair_t stopIndications = {

              .attrHandle = CY_BLE_REPORT_LAST_GENERAL_REPORT_CLIENT_CHARACTERISTIC_CONFIGURATION_DESC_HANDLE,

              .value.actualLen = 0,

              .value.len = 2,

              .value.val = clearIndication};

         

          cy_en_ble_gatt_err_code_t  stopError = Cy_BLE_GATTS_WriteAttributeValueLocal(&stopIndications);

          if (stopError == CY_BLE_GATT_ERR_NONE){

              if (!Cy_BLE_GATTS_IsIndicationEnabled(&connHandle,CY_BLE_REPORT_LAST_GENERAL_REPORT_CLIENT_CHARACTERISTIC_CONFIGURATION_DESC_HANDLE ))

                  DBG_PRINTF("No more indications to send. Indications disabled");

              else

                  DBG_PRINTF("Indications are still enabled");

          }

          else

          {DBG_PRINTF("Error to write in the Indications to stop %d\r\n" , stopError);}

      }

        • 1. Re: Writting local to send an indication
          NazarP_56

          Hello David,

          1.  Please, check in BT Configurator that you set correct length (it should be max length) for CY_BLE_REPORT_LAST_GENERAL_REPORT_CHAR. You can check this in tab GATT settings, or left side select you Report Last General Report Characteristic, and right side "Length" property (under field section). so if you have ".len = GENERAL_REPORT_SIZE, //47 bytes", the Length should be >= 47 bytes.

          2. Cy_BLE_GATTS_WriteAttributeValueLocal - does not allow to write CCCD. PS: Client is responsible to change CCCD state (and not application), CCCD flash area as zero after programing. Anyway if you need in some specific reason to do this, you can use Cy_BLE_GATTS_WriteAttributeValueCCCD but still do not recommend todo this.

          Regards,
          Nazar

          • 2. Re: Writting local to send an indication
            DaGa_4352226

            Hallo Nazar,

            I figuered out before that my Characteristic "Last General Report " had an other length. Also I read the API and also says that it does not allow to write CCCD.

             

            I have change my code to send Notifications but now I received other error code:

            Error with the notification 0x160001

            How is it this calculated? I dont now how to look for it.

             

            Thanks for you help. I hope you can guide me again

             

            Regards,

            David

            • 3. Re: Writting local to send an indication
              NazarP_56

              Hi David,
              Please refer to cy_en_ble_api_result_t enum for error details. We have following format for error:

              CY_PDL_STATUS_ERROR | CY_BLE_ID | <ERROR_NUMBER>, where CY_PDL_STATUS_ERROR - (2ul << 16u),  CY_BLE_ID - (5ul << 18u) and ERROR_NUMBER - 1...26. So 0x160001 is CY_BLE_ERROR_INVALID_PARAMETER.

              Main reasons to get CY_BLE_ERROR_INVALID_PARAMETER for Cy_BLE_GATTS_SendNotification:

              1. connHandle or handleValuePair are NULL,

              2. connHandle value is invalid.

               

              Regards,
              Nazar

              1 of 1 people found this helpful