I'm trying to communicate with a BLE data logger/sensor using rxBleAndroid running on both an Android phone as well as the Raspberry Pi using Android Things.
I'm currently having an issue, however, where up to about 5 of the first notifications are never received by my app.
I have verified that the BLE device is actually successfully sending all the expected notifications. I have done that through the nRF Connect app and everything works as expected through there.
When I do it through the nRF Connect app, these are the steps I take:
- Write to password characteristic to unlock device
- Write to mode characteristic to put device in correct mode
- Subscribe to notifications (and notifications immediately start working)
When doing it through RxAndroidBle, I suspect it may be that the .subscribe() is not being setup fast enough.
Is there maybe some way to do setupNotification(), and then write the characteristics to tell the device to start sending notifications?
Here is my current code:
rxBleClient = RxBleClient.create(this);
RxBleDevice device = rxBleClient.getBleDevice(mac_address);
device.establishConnection(false)
.flatMap(rxBleConnection -> rxBleConnection.writeCharacteristic(pword_uuid, pword)
.flatMap(ignored1 -> rxBleConnection.writeCharacteristic(mode_uuid, mode))
.flatMap(ignored2 -> rxBleConnection.setupNotification(log_uuid))
)
.flatMap(notificationObservable -> notificationObservable)
.subscribe(
bytes -> {
System.out.println(">>> data from device " + bytesToHex(bytes));
},
throwable -> {
System.out.println("error");
System.out.println(throwable);
});