Search code examples
androidbluetooth-lowenergykotlinotarxandroidble

rxAndroidBle get long write response


I'm doing a long write to a BLE for making an OTA update, but I need to wait for the write response of the BLE device for sending more data but I don't know how to catch the device write response, I'm using a Samsung galaxy tab s2 with android 7, and Kotlin for my code

override fun otaDataWrite(data:ByteArray) {
    manager.connection?.flatMap { rxBleConnection: RxBleConnection? -> rxBleConnection?.createNewLongWriteBuilder()
            ?.setCharacteristicUuid(OTACharacteristics.OTA_DATA.uuid)
            ?.setBytes(data)
            ?.setMaxBatchSize(totalPackages)
            ?.build()
    }?.subscribe({ t: ByteArray? ->
        Log.i("arrive", "data ${converter.bytesToHex(t)}")
        manageOtaWrite()
    }, { t: Throwable? -> t?.printStackTrace() })

every time that I write the characteristic the subscriptions respond me immediately with the written data, I need capture the response of the characteristic, for sending more data


Solution

  • Well, after a lot of testing, I finally develop a standalone class for the OTA update with the android BLE API, and I used it together with all my RxBle methods, I don't know if I have a hardware problem or something else, but I solve the problem, thanks a lot.