0

I am developing an android BLE application and I have successfully created the app which connects with the BLE peripheral. Right now Gatt server gets disconnected and reconnected again on interval of 30sec, I assume.

What I need is now to keep the connection alive in order to stream data into my data from peripheral. Why do I need that? Because it is an EMG sensor which a user would wear on the arm and plot real time data of muscle movement. I know that would reduce the battery life of the peripheral of EMG device but that doesn't matter in my case.

Does anyone have any suggestion to do that? Or Am I unaware of something which BLE offers?

I have modified this sample code for my peripheral https://github.com/googlesamples/android-BluetoothLeGatt

Deˣ
  • 4,191
  • 15
  • 24
B L Λ C K
  • 600
  • 1
  • 8
  • 24
  • Seems like a transaction is not completed correctly and therfore some side disconnects. Which side disconnects? What is the status parameter in the connection state change callback? – Emil Jun 19 '19 at 20:27
  • @Emil I get "BluetoothLe: Disconnected from GATT server." Can you suggest or provide a sample code or something? Any hint? I am so desperate to do this. – B L Λ C K Jun 20 '19 at 08:01

1 Answers1

1

you should implementation [onDescriptorWriteRequest] in [BluetoothGattServerCallback.] and then, it will maintaining connection each others.

like this:

override fun onDescriptorWriteRequest(device: BluetoothDevice?, requestId: Int, descriptor: BluetoothGattDescriptor?, preparedWrite: Boolean, responseNeeded: Boolean, offset: Int, value: ByteArray?) {
        super.onDescriptorWriteRequest(device, requestId, descriptor, preparedWrite, responseNeeded, offset, value)
        consoleOut("onDescriptorWriteRequest");

        server?.sendResponse(device , requestId , BluetoothGatt.GATT_SUCCESS , 0 , value);
    }