6 Replies Latest reply on May 29, 2016 10:47 AM by user_242978793

    Problems with custom characteristics (PSoc - Android)

    jesus.sola9_1581581

      Hello, I have a similar problem. I have a service with two characteristics ( temperature and humidity) and I created an android application to receive data from the characteristics, but I can not get one of them .

         

      This is the characteristic that if it works (temperature):

         

      cbtemp.setOnClickListener(new View.OnClickListener() { //CheckBox temperature

         

      @Override

         

      public void onClick(View view) {

         

      boolean isChecked = ((CheckBox) view).isChecked();

         

      if (isChecked) {

         

        BluetoothGattService mCustomService=mBluetoothLeService.getServices();

         

        BluetoothGattCharacteristic mCustomCharacteristic = mCustomService.getCharacteristic(UUID.fromString("00000002-0000-1000-   8000- 00805f9b34fb"));   //UUID characteristic temperature

         

        final int charaProp = mCustomCharacteristic.getProperties();

         

        if ((charaProp | BluetoothGattCharacteristic.PROPERTY_READ) > 0) {

         

          if (mNotifyCharacteristic != null) {

         

            mBluetoothLeService.setCharacteristicNotification(mNotifyCharacteristic, false);

         

            mNotifyCharacteristic = null;

         

            }

         

      mBluetoothLeService.readCharacteristic(mCustomCharacteristic); }

         

      if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {

         

          mNotifyCharacteristic = mCustomCharacteristic;

         

          mBluetoothLeService.setCharacteristicNotification(mCustomCharacteristic, true); }

         

      }

         

      });

         

      where getservices() function is :

         

      public BluetoothGattService getServices(){

         

      return mBluetoothGatt.getService(UUID.fromString("00000001-0000-1000-8000-00805f9b34fb"));  //UUID Service

         

      }

         

      For the characteristic humidity I do the same procedure but using the corresponding UUID (00000003-0000-1000-   8000-00805f9b34fb) but by clicking on the checkbox to activate it tells me :

         

      java.lang.NullPointerException : Attempt to invoke virtual method ' int android.bluetooth.BluetoothGattCharacteristic.getProperties () ' on a null object reference

         

      I'm really lost and not to do more . Thank you