androidkotlinbluetooth-lowenergybluetooth-gatt

How to write characteristics for bluetooth gatt service for two channels without getting disconnected(state 133)?


I've a bluetooth gatt service and two channels to write

bluetoothGattService = gatt?.getService(UUID.fromString(ble_gatt_service_uuid))

mTxCharacteristic1 = bluetoothGattService.getCharacteristic(UUID.fromString(txCharacteristics1))
mTxCharacteristic2 = bluetoothGattService.getCharacteristic(UUID.fromString(txCharacteristics2))

Now I have onCharacteristicsRead(), onCharacteristicsWrite(), and onCharacteristicsChange()

I connected with the ble device

When I write on mTxCharacteristic1 characteristic then ble works well

But whenever I write on mTxCharacteristic2 characteristic then ble gets DISCONNECTED

// function1
mTxCharacteristic1.writeType = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE
mTxCharacteristic1.value = chunk
gatt.writeCharacteristic(mTxCharacteristic1)

//function 2
mTxCharacteristic2.writeType = BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT
mTxCharacteristic2.value = chunk
gatt.writeCharacteristic(mTxCharacteristic2)

How to resolve this?

Everytime it is getting disconnected whenever I send data using 2nd characteristics, I'm only able to connect with ble again only when I restart my android device.

I tried:

gatt.beginReliableWrite()           
gatt.setCharacteristicNotification(characteristic1,true)
gatt.writeCharacteristic(characteristic1)
gatt.executeReliableWrite()
gatt.beginReliableWrite()
gatt.setCharacteristicNotification(characteristic2,true)
gatt.writeCharacteristic(characteristic2)
gatt.executeReliableWrite()

nrf connect app showing (TX(1) and unknown_characteristic(2))

still getting the same disconnected with gatt server issue with state 133.


Solution

  • Just made this simple writeCharacteristics instead of reliableWrite on doing this disconnection and no repairing issue resolved

    gatt.writeCharacteristic(characteristic1)

    gatt.writeCharacteristic(characteristic2)

    I was have 8 byte of packet data where I sent null which I found on debugging

    expected was 19 byte array and I was sending only 11 packets (8 missed)

    due to this it was giving me error and getting disconnected with state code 133