0

What I am trying to do:

I am building an android ble application which will connect to IOT devices and when sending command it will return with some responses.

For example when sending "STATUS" it will return with "STATUS OK"

What is being done:

Using connectGatt method I have established the connection between phone and device. Once the connection is established on service discovered is being called and in result I got service and its characteristic's with UUID's to interact with device.

GATT client method to connect:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    device!!.connectGatt(context, false, callback, BluetoothDevice.TRANSPORT_LE)
} else {
    device!!.connectGatt(context, false, callback)
}

Service and its Characteristics discovered:

Service 569a1101-b87f-490c-92cb-11ba5ea5167c
Characteristics:
|--569a2000-b87f-490c-92cb-11ba5ea5167c: NOTIFIABLE
|------00002902-0000-1000-8000-00805f9b34fb: EMPTY
|--569a2001-b87f-490c-92cb-11ba5ea5167c: WRITABLE, WRITABLE WITHOUT RESPONSE
|--569a2002-b87f-490c-92cb-11ba5ea5167c: NOTIFIABLE
|------00002902-0000-1000-8000-00805f9b34fb: EMPTY
|--569a2003-b87f-490c-92cb-11ba5ea5167c: WRITABLE, WRITABLE WITHOUT RESPONSE

In the above four characteristics

1 (569a2000-b87f-490c-92cb-11ba5ea5167c) and 3 (569a2002-b87f-490c-92cb-11ba5ea5167c) is for enabling/disabling notification using writeDescriptor

2 (569a2001-b87f-490c-92cb-11ba5ea5167c) is for writing the commands ( STATUS in our case) using characteristicWrite

4 (569a2003-b87f-490c-92cb-11ba5ea5167c) is for sending signal to device that GATT client is ready to receive data. In our case we are using if we send 1 it means GATT is ready to accept data, if we send 0 it means GATT client will no longer listen to data emitted from device.

So after I have got the charateristics from devices,

First I am enabling notification for characteristics 1, 3

Second I am writing value "1" on characteristics 4 to let device know that GATT client is ready to accept data.

Third I am sending the command "STATUS" in characteristic 2.

What is Happening

When I send "STATUS" in writeCharacteristic in (569a2001-b87f-490c-92cb-11ba5ea5167c). I got the data response "STATUS OK" from device in onCharacteristicChanged callback.

When I send the "STATUS" second time I am not getting any response. The onCharacteristicChanged is not called during the second time.

What I tried to solve

I tried to enable the notifications every time before sending the command and disable the notification after I got the response first time, but still no callback on second time.

Help

Please help me get a solution for this issue? If you any have faced similar issue, please share your suggestions to try out. Thanks

Sabarinathan
  • 439
  • 1
  • 7
  • 19

0 Answers0