Git Product home page Git Product logo

Comments (6)

dariuszseweryn avatar dariuszseweryn commented on May 18, 2024

Unsubscribing from connection subscription should take place once you're no longer interested in connecting.
For instance - sometimes you're interested in showing the device state in the Activity. In this situation you should unsubscribe from the conSubscription in onPause() method.
Sometimes the application needs to execute a specific flow when connecting to the device and then it's done - let's say we want to read a value from a characteristic and disconnect:

rxBleDevice.establishConnection(context, false)
  .flatMap(connection -> connection.readCharacteristic(characteristicUuid))
  .take(1)
  .subscribe(readBytes -> /* do your thing with readBytes */)

In this situation the establishConnection() subscription will be automatically unsubscribed by the take(1) operator. We can do it this way if we're not updating anything UI related inside an Activity which can be destroyed b the time the readBytes will be available,

from rxandroidble.

zzt93 avatar zzt93 commented on May 18, 2024

@dariuszseweryn
The take(1) corresponds to another device's one writeCharacteristic() invocation, no matter how big the characteristic is? In other word, if one device invoke writeCharacteristic twic, another device have to readCharacteristic() twice to read all info( or take(2) in this case)?

from rxandroidble.

dariuszseweryn avatar dariuszseweryn commented on May 18, 2024

@zzt93 - Excuse me but I cannot really follow you. Could you rephrase the question?

The RxAndroidBle library is for client side only. So the client knows what to read from the server or it waits for read notifications usually. The implementation of the server may vary greatly so it is hard for me to know what you have in mind.

Basically .take(1) takes exactly one event from the above observable and unsubscribes from it. Unsubscribing from .establishConnection() closes the connection. .readCharacteristic() is returning an Observable that will emit only once.

Does it answer your question?

from rxandroidble.

zzt93 avatar zzt93 commented on May 18, 2024

Say we have two devices all use RxAndroidBle to connect to each other. One device call writeCharacteristic() twice during connection, the other device then call readCharacteristic() to read. Will the second device observe one event or two?

from rxandroidble.

dariuszseweryn avatar dariuszseweryn commented on May 18, 2024

You cannot directly connect two Android devices to each other because the RxAndroidBle is a client library and BLE connection is a client-server connection. Android has introduced BLE server API though it is not covered in the library.

Either way both readCharacteristic() and writeCharacteristic() are client initiated, one-time, actions.

from rxandroidble.

zzt93 avatar zzt93 commented on May 18, 2024

Ok, I know. Thank you.

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.