I'm trying to receive data in mobile(android) devices from a BLE device based on nRF52840 and custom firmware.
Here is my setting
- sampling rate : 250Hz
- mobile devices : Galaxy flip z 3, Galaxy S22
- Used library : RxBleAndroid
To check whether the BLE device sends data correctly or not, I tested it using nRF Connect for Desktop. There were about 250 samples per second. (nRF52840 dongle was equipped with the Desktop)
However, in mobile devices, there were about 20~30 samples per second. I already checked these mobile devices could receive 250 samples per second using a commercial device. So I think it is not a problem of mobile devices, but code.
Here is my code
fun connectDevice(){
rxBleDevice = rxBleClient.getBleDevice(lxDeviceAddress)
connectSubscription = rxBleDevice.establishConnection(false)
.subscribe(
{ rxBleConnection ->
this.rxBleConnection = rxBleConnection
Log.v(TAG, "success to connect")
}
) { throwable ->
throwable.printStackTrace()
}
}
fun bleNotification() = rxBleConnection
.setupNotification(lxDeviceUUID)
?.doOnNext { notificationObservable->
}
fun readDataFromDevice(){
scanSubscription.dispose()
bleNotification()
?.observeOn(io.reactivex.rxjava3.android.schedulers.AndroidSchedulers.mainThread())
?.flatMap { notificationObservable -> notificationObservable }
?.subscribe({ bytes ->
Log.v(TAG, byteArrayToHex(bytes))
}, { throwable ->
throwable.printStackTrace()
})
}
I called connectDevice() to connect the BLE device, and called readDataFromDevice() to read data.
Could you give me some solutions?