4 Replies Latest reply on Jun 10, 2016 8:08 AM by userc_26240

    Sending data to a WICED SENSE BLE device through WICED SENSE app

    userc_26240

      Hello,

       

      I am trying to send data to a WICED SENSE BLE device through WICED SENSE app. I've  added the following code into  the a  WICED SENSE app source code, especially in the GattRequestManager. hust for testing I've used ota service:

       

      @public boolean send(byte[] data) {

          BluetoothGattService Bgs=  findService(UUID_WS_SECURE_UPGRADE_SERVICE);
          if (mGatt == null || Bgs== null) {
              Log.w(TAG, "BluetoothGatt not initialized");
              return false;
          }

          BluetoothGattCharacteristic characteristic =
                  Bgs.getCharacteristic(UUID_WS_SECURE_UPGRADE_CHARACTERISTIC_APP_INFO );

          if (characteristic == null) {
              Log.w(TAG, "Send characteristic not found");
              return false;
          }

          characteristic.setValue(data);
          characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
          return mGatt.writeCharacteristic(characteristic);
      }


      And the findService() is as follows:

      public BluetoothGattService findService(UUID uuid) {

         if (uuid == null) {

         return null;

        }

          List<BluetoothGattService> services = mGatt.getServices();

         if (services == null) {

         return null;

        }

        Iterator<BluetoothGattService> i = services.iterator();

         while (i.hasNext()) {

        BluetoothGattService s = i.next();

         if (uuid.equals(s.getUuid())) {

         return s;

        }

        }

         return null;

      }

       

      I call the send(byte[] data) as follows from the mainActivity:

       

      Button one= (Button) findViewById(R.id.send);

      one.setOnClickListener(new OnClickListener() {

         @Override
         public void onClick(View v) {

      String mode = "3";

      GattRequestManager GM=new GattRequestManager(this, bluetoothDevice);

      GM.send(mode.getBytes())

        }

      });

       

      I after clicking of the button I get an error message in the GattRequestManger class  in the method findService()  at List<BluetoothGattService> services = mGatt.getServices();

      saying Attempt to invoke virtual method 'java.util.List android.bluetooth.BluetoothGatt.getServices()' on a null object reference I am lost here. I did run the app in debug mode and found out

      it runs perfectly when the reading are received from the sensors. Any kind of help is appreciated.  jaeyoung jota_1939431

       

      Regards,

      Adarsh