Code Monkey home page Code Monkey logo

Comments (9)

farmazon3000 avatar farmazon3000 commented on July 30, 2024 2

So this is what I have to automatically try to connect to device after disconnect happens with 5 seconds delay:

rxBleDevice.establishConnection(context, false) // <-- autoConnect flag
    .doOnError(throwable -> {
        Log.d(TAG, "rxBleConnection doOnError: " + throwable);
    })
    .retryWhen(new Func1<Observable<? extends Throwable>, Observable<?>>() {
        @Override
        public Observable<?> call(Observable<? extends Throwable> errorNotification) {
            return errorNotification
                    .flatMap(new Func1<Throwable, Observable<?>>() {
                        @Override
                        public Observable<?> call(Throwable throwable) {
                            Log.v(TAG, "connect retrying...");
                            return Observable.timer(5, TimeUnit.SECONDS);
                        }
                    });
        }
    })
    .subscribe(rxBleConnection -> {
        Log.d(TAG, "rxBleConnection: " + rxBleConnection);
    });

from rxandroidble.

uKL avatar uKL commented on July 30, 2024 1

This is expected behavior. Once disconnected you need to establish the connection manually again. Why do you think that it should be anyway different?

from rxandroidble.

uKL avatar uKL commented on July 30, 2024

The library notifies you that the connection has been lost but you need to call establish connection again to reconnect. Is that the case?

from rxandroidble.

dlykoits avatar dlykoits commented on July 30, 2024

yes

from rxandroidble.

dlykoits avatar dlykoits commented on July 30, 2024

Sorry, misunderstood you.
I just call this code again when connection state change(disconnected) appear.
and nothing happened.

from rxandroidble.

uKL avatar uKL commented on July 30, 2024

Could you provide code sample and preferably logs from RxAndroidBle?

from rxandroidble.

dlykoits avatar dlykoits commented on July 30, 2024

Please look at sources: https://github.com/dlykoits/RxAndtoidBLESample.git
Steps to reproduce:

  1. press connect -> ble device connected
  2. then turn off ble device - > connection lost
  3. turn on ble device
  4. press connect
    Actual result:
    connection establishment doesn't work, "disconnected" status appear immediately after establish call
    Expected result:
    connection established again

from rxandroidble.

dariuszseweryn avatar dariuszseweryn commented on July 30, 2024

What I see is that you're trying to reuse a Subscriber here and that is a misuse as the Subscriber is stateful and therefore cannot be reused. It was already failed once and is probably unsubscribing automatically.
You can try either to create a new Subscriber for each subscription or to use an Observer instead - which is stateless.

from rxandroidble.

dlykoits avatar dlykoits commented on July 30, 2024

You right, Thanks a lot!!!
P.S.: I started learning RX week ago.

from rxandroidble.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.