0

I am working on an BLE apps using google ble sdk , I testing on samsung s4(4.3) , sony z1 compact(4.3) , htc new one(4.4) but only samsung s4 just abnormal

the question is when calling setCharacteristicNotification(boolean enable) if i get onDescriptorWrite call back ,then start get notify data about 5 ~ 6 seconds i will got gatt service disconnect callback , and my log just output 9 times , as normal log will output 42 times ,

sorry for my poor english , i just using my code and log to help anyone can understand my problem

setCharacteristicNotification

public boolean setCharacteristicNotification(boolean enabled){


      if (mBluetoothAdapter == null || mBluetoothGatt == null) {
          Log.w(TAG, "BluetoothAdapter not initialized");
               return false;      
      }

      BluetoothGattService Service = 
              mBluetoothGatt.getService
              (UUID.fromString(GattAttributes.SONOSTAR_SENSOR_UUID));
      if (Service == null) {
          Log.e(TAG, "service not found!");
          return false;
      }

      BluetoothGattCharacteristic characteristic = 
              Service.getCharacteristic
              (UUID.fromString(GattAttributes.SONOSTAR_NOTIFY_R));

      final int charaProp = characteristic.getProperties();

      if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {
          mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);

            BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
                    UUID.fromString(GattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
            descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); 

            mBluetoothGatt.writeDescriptor(descriptor);

          return true;
      }

    return false;

}

onCharacteristicChanged

@Override
    public void onCharacteristicChanged(BluetoothGatt gatt,
            BluetoothGattCharacteristic characteristic) 
    {

        Log.i(TAG, "on notify" +"");
            NOTIFY_DATA_ARRAY.add(characteristic.getValue());
            Log.i(TAG, NOTIFY_DATA_ARRAY.size() + " "+characteristic.getValue());
    }

my log

03-30 18:33:50.985: D/BluetoothGatt(8240): setCharacteristicNotification() - uuid: 0000ffb5-0000-1000-8000-00805f9b34fb enable: true
03-30 18:33:50.985: D/BluetoothGatt(8240): writeDescriptor() - uuid: 00002902-0000-1000-8000-00805f9b34fb
03-30 18:33:51.055: D/BluetoothGatt(8240): onDescriptorWrite() - Device=20:CD:39:90:A2:9B UUID=0000ffb5-0000-1000-8000-00805f9b34fb
03-30 18:33:51.055: I/BluetoothLeService(8240): android.bluetooth.BluetoothGatt@436e0190 gatt
03-30 18:33:51.055: I/BluetoothLeService(8240): android.bluetooth.BluetoothGattDescriptor@436f8bf0 descriptors
03-30 18:33:51.055: I/BluetoothLeService(8240): 0 status
03-30 18:33:51.055: D/BluetoothLeService(8240): Callback: Wrote GATT Descriptor successfully.
03-30 18:33:51.545: D/BluetoothGatt(8240): onNotify() - Device=20:CD:39:90:A2:9B UUID=0000ffb5-0000-1000-8000-00805f9b34fb
03-30 18:33:51.545: I/BluetoothLeService(8240): on notify
03-30 18:33:51.545: I/BluetoothLeService(8240): 1 [B@436fd2f0
03-30 18:33:52.030: D/BluetoothGatt(8240): onNotify() - Device=20:CD:39:90:A2:9B UUID=0000ffb5-0000-1000-8000-00805f9b34fb
03-30 18:33:52.035: I/BluetoothLeService(8240): on notify
03-30 18:33:52.035: I/BluetoothLeService(8240): 2 [B@43700d80
03-30 18:33:52.520: D/BluetoothGatt(8240): onNotify() - Device=20:CD:39:90:A2:9B UUID=0000ffb5-0000-1000-8000-00805f9b34fb
03-30 18:33:52.520: I/BluetoothLeService(8240): on notify
03-30 18:33:52.520: I/BluetoothLeService(8240): 3 [B@437044f8
03-30 18:33:53.055: D/BluetoothGatt(8240): onNotify() - Device=20:CD:39:90:A2:9B UUID=0000ffb5-0000-1000-8000-00805f9b34fb
03-30 18:33:53.055: I/BluetoothLeService(8240): on notify
03-30 18:33:53.055: I/BluetoothLeService(8240): 4 [B@43707d00
03-30 18:33:53.545: D/BluetoothGatt(8240): onNotify() - Device=20:CD:39:90:A2:9B UUID=0000ffb5-0000-1000-8000-00805f9b34fb
03-30 18:33:53.545: I/BluetoothLeService(8240): on notify
03-30 18:33:53.545: I/BluetoothLeService(8240): 5 [B@4370b488
03-30 18:33:54.030: D/BluetoothGatt(8240): onNotify() - Device=20:CD:39:90:A2:9B UUID=0000ffb5-0000-1000-8000-00805f9b34fb
03-30 18:33:54.030: I/BluetoothLeService(8240): on notify
03-30 18:33:54.030: I/BluetoothLeService(8240): 6 [B@4370eba0
03-30 18:33:54.520: D/BluetoothGatt(8240): onNotify() - Device=20:CD:39:90:A2:9B UUID=0000ffb5-0000-1000-8000-00805f9b34fb
03-30 18:33:54.520: I/BluetoothLeService(8240): on notify
03-30 18:33:54.520: I/BluetoothLeService(8240): 7 [B@43712178
03-30 18:33:55.055: D/BluetoothGatt(8240): onNotify() - Device=20:CD:39:90:A2:9B UUID=0000ffb5-0000-1000-8000-00805f9b34fb
03-30 18:33:55.055: I/BluetoothLeService(8240): on notify
03-30 18:33:55.055: I/BluetoothLeService(8240): 8 [B@437157b0
03-30 18:33:55.540: D/BluetoothGatt(8240): onNotify() - Device=20:CD:39:90:A2:9B UUID=0000ffb5-0000-1000-8000-00805f9b34fb
03-30 18:33:55.540: I/BluetoothLeService(8240): on notify
03-30 18:33:55.545: I/BluetoothLeService(8240): 9 [B@43718d88
03-30 18:34:20.310: D/BluetoothGatt(8240): onClientConnectionState() - status=0 clientIf=6 device=20:CD:39:90:A2:9B
03-30 18:34:20.310: I/BluetoothLeService(8240): Disconnected from GATT server.
03-30 18:34:20.320: I/HomeActivity(8240): ACTION_GATT_DISCONNECTED onReceive
03-30 18:34:20.395: E/ViewRootImpl(8240): sendUserActionEvent() mView == null
Cœur
  • 37,241
  • 25
  • 195
  • 267
timmyB
  • 39
  • 5

2 Answers2

0

From your log define that server disconnect call . so might be some period of time ble server disconnected (some time define in ble server ). So if samsung device take time to read notification data device disconnect it self .

mcd
  • 1,434
  • 15
  • 31
  • yes , if i using write/read/notify , then s4 will be disconnect after 30 seconds , but when i calling setCharacteristicNotification , the data transmission has no complete , that is my issue. it's so strange – timmyB Apr 02 '14 at 06:50
0

After enable notification just read explicitly once as shown in below code for samsung device.

work around

         try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        mBluetoothGatt.readCharacteristic(characteristic);

notification will start . Tt works but not work when communication is going on both way way (Client to server and server to client continuous on same charecteristic ).

Gopal Sharma
  • 300
  • 4
  • 14