0

I am new to developing BLE stuff. So I am using Android 5.1, I need to send more than 20 byte data over BluetoothGATT. So onServicesDiscovered() callback, I did the following:

@Override
    public void onServicesDiscovered(BluetoothGatt gatt, int status){
        Log.d(TAG, "Services discovered " + status);
        if(status == 0)
        {
            mHandler.sendMessage(Message.obtain(null, MSG_PROGRESS, "Enabling Sensor..."));
        
            enableSensor(gatt);
            //enableNotification(gatt);
            boolean mtuStatus = gatt.requestMtu(512);
            Log.d(TAG, "mtu status: " + mtuStatus);
        }
        else
        {
            Log.d("TAG", "Services not discovered properly: " + status); 
        }
            
    }

the mtuStatus returned is true. But when I writecharacteristic to device, it gives me error code 6.

I have also implemented onMtuChanged Callback which is never triggered.

@Override
    public void onMtuChanged(BluetoothGatt gatt, int mtu, int status){
        Log.d(TAG, "new mtu: " + mtu + "status: " + status);
    }

What am I missing?

halfer
  • 19,824
  • 17
  • 99
  • 186
Samra
  • 1,815
  • 4
  • 35
  • 71
  • You are missing the fact that you can only send 20 bytes at a time over a GATT attribute. You will need to break your data into 20 byte chunks and send it that way – Paulw11 Aug 15 '16 at 07:32
  • What type of device are you connecting to? Do you know what Bluetooth features it supports? – Eirik M Aug 15 '16 at 08:41

0 Answers0