I created my own bluetooth service that manages ble sensors. I am having troubles when I try to pair new sensors. It connects successfully but when rxandroidble calls setCharacteristicNotification() and it returns true
after less than one second it returns enable: false
Here is the logcat:
D/BluetoothGatt: setCharacteristicNotification() - uuid: 00002a37-0000-1000-8000-00805f9b34fb enable: true
D/BluetoothGatt: setCharacteristicNotification() - uuid: 00002a37-0000-1000-8000-00805f9b34fb enable: false
so the sensor is connected but I can't get any data from that sensor.
Here is the code I use to start the service:
startService(new Intent(this, BluetoothTracker.class));
((User) getApplicationContext()).setServiceConnection(new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
((User) getApplicationContext()).setBluetoothTracker(((BluetoothTracker.MyLocalBinder) iBinder).getService());
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
}
});
bindService(new Intent(this, BluetoothTracker.class), ((User) getApplicationContext()).getServiceConnection(), BIND_AUTO_CREATE);
When I start app this always works, only when I pair a new sensor I get this problem.
Here is the setupNotification function that seems to have the problem but I can't figure out what is happening
private static void setupNotify(RxBleConnection connection, UUID uuid, IGattCharacteristicHandler handler) {
connection.getCharacteristic(uuid).subscribe(characteristic -> {
Observable<byte[]> notification = connection.setupNotification(characteristic, NotificationSetupMode.QUICK_SETUP).flatMap(notificationObservable -> notificationObservable);
notification.subscribe(handler::handle, e -> Log.e(TAG, "BleException:" + e.getMessage()));
}, throwable -> Log.e(TAG, "setupNotify::ERROR " + throwable.getMessage()));
}