Giter Club home page Giter Club logo

rxbluetooth's People

Contributors

carlemil avatar darkosmoljo avatar ecdpalma avatar ivbaranov avatar pierreroth64 avatar qwildz avatar rancbar avatar robholmes avatar vanniktech avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rxbluetooth's Issues

Wish list

  • sending and receiving data
  • profiles
    - [ ] manage connection as client/server
    - [ ] ble?

observeDevices works on 5.1 but not on 6.0

Hi,

I'm trying out this library and it looks great so far, with a minor issue I hope. I cant get the observeDevices to work on 6.0 and higher android version. I never get any callbacks and cant see any of the surrounding devices. What more data/info could I supply you with to help with debugging?

Socket not created exception

I am getting following exception when I'm not able to connect to bluetooth device and then I navigate to some other page. Is there any way to catch this exception in my code?

E/System:Uncaught exception thrown by finalizer
E/System: java.io.IOException: socket not created
at android.net.LocalSocketImpl.shutdownInput(LocalSocketImpl.java:404)
at android.net.LocalSocket.shutdownInput(LocalSocket.java:207)
at android.bluetooth.BluetoothSocket.close(BluetoothSocket.java:801)
at android.bluetooth.BluetoothSocket.finalize(BluetoothSocket.java:309)
at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:222)
at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:209)

mSubscriptionConnectDevice = mRxBluetooth.observeConnectDevice(mBluetoothDevice, uuid)
 .observeOn(AndroidSchedulers.mainThread())
 .subscribeOn(Schedulers.computation())
 .subscribe(new Action1 < BluetoothSocket > () {
  @Override
  public void call(BluetoothSocket bluetoothSocket) {
   try {
    mBluetoothConnection = new BluetoothConnection(bluetoothSocket);
    startReadingBluetoothData(); // this method starts read data subscription
   } catch (Exception e) { // This didn't catch any exception
    Log.e(TAG, "Error bluetooth connection:" + e.getMessage());
    if (bluetoothSocket != null) {
     try {
      bluetoothSocket.close();
     } catch (IOException e1) {
      Log.e(TAG, "IOException: " + e1.getMessage());
     }
    }
   }
  }
 }, new Action1 < Throwable > () {
  @Override
  public void call(Throwable throwable) {
   Log.e(TAG, "Error bluetooth connection: " + throwable.getMessage()); // I get this log message before getting that IOException : socket not created 
  }
 });

(0.1.6) observeConnectDevice working on the main thread

Hi I am using version 0.1.6

And every time I try to connect to some device, the app hangs and it shows how many frames were skipped.

rxBluetooth.observeConnectDevice(btDevice, uuid)
                .subscribeOn(AndroidSchedulers.mainThread())
                .observeOn(Schedulers.computation())
                .subscribe({
                    println(btDevice.name)
                    bluetoothConnection = BluetoothConnection(it)
                    busProvider.post(RxBluetoothBusEvent().BluetoothDeviceConnected())
                },{
                    it.printStackTrace()
                    busProvider.post(RxBluetoothBusEvent().Exception(it))
                })

This is my code. Am I doing something wrong or its a bug in the library?

Thanks

Set Pin

Hi
Is there any way to perform pairing pin?
My target device is HC-05 module that requires pin to connect.

(0.1.6) Disconnecting from device

When I force close the application and open it again it automatically tries to connect to the same device, but it says that the socket timed out -1.

Before your library I was using the default one from Android and there I didnt had this problem.

What should I do before connecting to the device? Is there a possibility to disconnect before connecting?
Thanks

observeStringStream() generating extra response

I'm getting "" strings after each string/message is received. I've created an HCI log to confirm my bluetooth device was sending the message format I expected. It is sending a single JSON response that terminates ends with }\r\n
Inspecting the code for observeStringStream() it calls observeStringStream with \r,\n as the delimiter. The onNext is emitting when the first delimiter is found instead of waiting to match both. The result is the buffer is cleared then emit is called again when it reads the next byte which will match the \n. This time the buffer is empty because it was just cleared so the then in emit() line 160 is called sending a blank "" string.

If the delimiter is \r\n then the behavior I was expecting was just the string in my case the json {} should be returned correct?

` @OverRide public void onNext(Byte b) {
boolean found = false;
for (int d : delimiter) {
if (b == d) {
found = true;
break;
}
}

image
`

Consider Dropping ACCESS_FINE_LOCATION

We need a location permission to use Bluetooth. The manifest for the library, though, requests both. This means that apps need to explicitly remove ACCESS_FINE_LOCATION if the developer does not want it, using:

  <uses-permission
    android:name="android.permission.ACCESS_FINE_LOCATION"
    tools:node="remove" />

I am uncertain what benefit there is in the library declaring both permissions, so I am hoping that you will consider only including ACCESS_COARSE_LOCATION, which is sufficient for Bluetooth MAC address access, at least based on my tests to date.

Thanks for considering this!

enableBluetooth() with null adapters cause null pointer exeption.

if (!rxBluetooth.isBluetoothAvailable()) {
  // to enable blutooth via startActivityForResult()
  rxBluetooth.enableBluetooth(this, REQUEST_ENABLE_BT);
} else {
 // makeFun
}

For device that not support BT at all this function cause NPE.

You have to check if mBluetoothAdapter is not a null object inside enableBluetooth or add additional functions to check if BT is available at all.

observeDevices() not return any new device until you not start observing through settings menu

observeDevices() not return any new device until you not start observing through settings menu.
When I go to the main menu and go to bluetooth settings it start return new devices in my subscriber too. No errors return, just nothing.
Permissions was acquired. Android 7
My code:

override fun observinBlDevices(consumer: Consumer<BluetoothDevice>, errorConsumer: Consumer<Throwable>) {
        if (blReady().not()) return
        disposal.add(rxBluetooth.observeDevices()
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.computation())
                .subscribe(consumer, errorConsumer))
    }

Version 2.1.0 unavailable

Hi,

It seems that version 2.1.0 is not available, despite being shown in the README:
compile 'com.github.ivbaranov:rxbluetooth2:2.1.0'

Wait for incoming connection

How do you wait for new connection?
Do I have use RxBluetooth.observeConnectionState + RxBluetooth.observeConnectDevice?

Suggestion: add btAdapter.getBondedDevices()

Hi,
thanks for your nice work!
I have a pretty basic suggestion though:
Adding a wrapper for BluetoothAdapter.getBondedDevices() would be very nice, as this should be the preferred way of connecting to a device which has been discovered and connected before.

Exception: Read failed, socket might closed or timeout, read ret: -1

Hi, I'am trying to send data to device when user click a button. First time everything is OK. But, when I click the button second time, I receive IOException exception with message "Read failed, socket might closed or timeout, read ret: -1". The problem is in bluetoothSocket.connect(); function. It's android problem after android 4.2.

Exceptions

Hi! I have problem with next:

  1. I do close connect with BluetoothConnection and recive next exception to RX onError ->
    com.github.ivbaranov.rxbluetooth.exceptions.ConnectionClosedException Can't read stream
    at com.github.ivbaranov.rxbluetooth.BluetoothConnection$1.subscribe(BluetoothConnection.java88)
    at io.reactivex.internal.operators.flowable.FlowableCreate.subscribeActual(FlowableCreate.java72)
    at io.reactivex.Flowable.subscribe(Flowable.java13234)
    at io.reactivex.internal.operators.flowable.FlowablePublish.connect(FlowablePublish.java130)
    at io.reactivex.internal.operators.flowable.FlowableRefCount.subscribeActual(FlowableRefCount.java138)
    at io.reactivex.Flowable.subscribe(Flowable.java13234)
    at io.reactivex.Flowable.subscribe(Flowable.java13183)
    at io.reactivex.internal.operators.flowable.FlowableLift.subscribeActual(FlowableLift.java49)
    at io.reactivex.Flowable.subscribe(Flowable.java13234)
    at io.reactivex.internal.operators.flowable.FlowableOnBackpressureBuffer.subscribeActual(FlowableOnBackpressureBuffer.java46)
    at io.reactivex.Flowable.subscribe(Flowable.java13234)

  2. I do dispose to observeStringStream
    I again received above error in main thread.

observeConnectionState not work

image
I add rxBluetooth.observeConnectionState() to your demo,but when I close the bluetooth(not phone’s),print nothing.

Problem with importing module

Hello,

I have added dependancy for RxBluetooth, but I am getting an error:
Error:(22, 13) Failed to resolve: com.github.ivbaranov:rxbluetooth2:2.0.0-SNAPSHOT
I have attached my gradle file.

Thank you

app_build_gradle.txt

Observing connection / bond states not working !?

Hi,

This lib is great, I really enjoy using it, thanks for the good work!
I still fail observing connection & bond states.

This is how I make the subscriptions, in you example code, in the initEventListeners method:

For connection state:

compositeDisposable.add( rxBluetooth.observeConnectionState()
             .observeOn( AndroidSchedulers.mainThread() )
             .subscribeOn( Schedulers.computation() )
             .subscribe(
                     new Consumer<ConnectionStateEvent>()
                     {
                         @Override
                         public void accept( ConnectionStateEvent event ) throws Exception
                         {
                             switch( event.getState() )
                             {
                                 case BluetoothAdapter.STATE_DISCONNECTED:
                                     showToast( "STATE_DISCONNECTED" );
                                     break;
                                 case BluetoothAdapter.STATE_CONNECTING:
                                     showToast( "STATE_CONNECTING" );
                                     break;
                                 case BluetoothAdapter.STATE_CONNECTED:
                                     showToast( "STATE_CONNECTED" );
                                     break;
                                 case BluetoothAdapter.STATE_DISCONNECTING:
                                     showToast( "STATE_DISCONNECTING" );
                                     break;
                             }
                         }
                     } ) );

For bond state:

compositeDisposable.add( rxBluetooth.observeBondState()
            .observeOn( AndroidSchedulers.mainThread() )
            .subscribeOn( Schedulers.computation() )
            .subscribe( new Consumer<BondStateEvent>()
            {
                @Override
                public void accept( BondStateEvent event ) throws Exception
                {
                    switch( event.getState() )
                    {
                        case BluetoothDevice.BOND_NONE:
                            showToast( "BOND_NONE" );
                            break;
                        case BluetoothDevice.BOND_BONDING:
                            showToast( "BOND_BONDING" );
                            break;
                        case BluetoothDevice.BOND_BONDED:
                            showToast( "BOND_BONDED" );
                            break;
                    }
                }
            } ) );

After connecting to a scanned device:

rxBluetooth.connectAsClient( device, UUID );

I never get any bond nor connection messages.

Am I missing something!?

Thanks

Artifact Missing, or Documentation Problem

https://github.com/IvBaranov/RxBluetooth#download

This says that the current version is 2.0.0, which is new; it had been 2.0.0-SNAPSHOT previously. However, I cannot find 2.0.0 anywhere:

  • It's not in the snapshots repo, the way the documentation suggests

  • It's not in Maven Central

  • JCenter's search is seriously messed up, so I don't know if it is there, but jcenter() isn't finding it in a Gradle build, even with --refresh-dependencies:

* What went wrong:
Could not resolve all files for configuration ':app:debugCompileClasspath'.
> Could not find com.github.ivbaranov:rxbluetooth2:2.0.0.
  Searched in the following locations:
      file:/opt/android-sdk-linux/extras/m2repository/com/github/ivbaranov/rxbluetooth2/2.0.0/rxbluetooth2-2.0.0.pom
      file:/opt/android-sdk-linux/extras/m2repository/com/github/ivbaranov/rxbluetooth2/2.0.0/rxbluetooth2-2.0.0.jar
      file:/opt/android-sdk-linux/extras/google/m2repository/com/github/ivbaranov/rxbluetooth2/2.0.0/rxbluetooth2-2.0.0.pom
      file:/opt/android-sdk-linux/extras/google/m2repository/com/github/ivbaranov/rxbluetooth2/2.0.0/rxbluetooth2-2.0.0.jar
      file:/opt/android-sdk-linux/extras/android/m2repository/com/github/ivbaranov/rxbluetooth2/2.0.0/rxbluetooth2-2.0.0.pom
      file:/opt/android-sdk-linux/extras/android/m2repository/com/github/ivbaranov/rxbluetooth2/2.0.0/rxbluetooth2-2.0.0.jar
      https://dl.google.com/dl/android/maven2/com/github/ivbaranov/rxbluetooth2/2.0.0/rxbluetooth2-2.0.0.pom
      https://dl.google.com/dl/android/maven2/com/github/ivbaranov/rxbluetooth2/2.0.0/rxbluetooth2-2.0.0.jar
      https://jcenter.bintray.com/com/github/ivbaranov/rxbluetooth2/2.0.0/rxbluetooth2-2.0.0.pom
      https://jcenter.bintray.com/com/github/ivbaranov/rxbluetooth2/2.0.0/rxbluetooth2-2.0.0.jar
      https://oss.sonatype.org/content/repositories/snapshots/com/github/ivbaranov/rxbluetooth2/2.0.0/rxbluetooth2-2.0.0.pom
      https://oss.sonatype.org/content/repositories/snapshots/com/github/ivbaranov/rxbluetooth2/2.0.0/rxbluetooth2-2.0.0.jar
  Required by:
      project :app

I am not certain if the documentation is citing the wrong artifact version (or the wrong artifact location) or if I am just totally screwing this up somehow.

Thanks!

Observing connection failing

Every time I try to connect to any Android device and subscribe Observable to wait for bytes from connection it fails with IOException: "read failed, socket might closed or timeout, read ret: -1".

Beacon.getDistance totally returns different values on different devices

I wrote an app using this library to show nearby beacons and distances between the device and beacon. The problem is even having two different phones running the same app and couple of beacons around I can see the distance values differs significantly.
I use
Becon.getDistance
method.
Any suggestions?

read failed, socket might closed or timeout, read ret: -1

Hi when i try to make a connection with a device it gives me this error

read failed, socket might closed or timeout, read ret: -1

After making a connection with the device , the phone send a connection request with a pair number and the other phone accepts it , but it still gives me the error.
this is my code
rxBluetooth.observeDevices() .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribe(new Consumer<BluetoothDevice>() { @Override public void accept(BluetoothDevice bluetoothDevice) throws Exception { if(bluetoothDevice.getName() != null && bluetoothDevice.getName().equals("Test")) { Log.e("RxBt",bluetoothDevice.getName()); rxBluetooth.cancelDiscovery(); connectToDevice(bluetoothDevice); } if(bluetoothDevice.getAddress() != null) Log.e("RxBt",bluetoothDevice.getAddress()); //addDevice(bluetoothDevice); } });

Connecting to device method

private void connectToDevice(BluetoothDevice bluetoothDevice) { Log.e("connectToDevice()","connectToDevice invoked."); UUID uuid = UUID.fromString("f77d314e-9730-4a0b-a3a8-0d283eff53ea"); rxBluetooth.observeConnectDevice(bluetoothDevice, uuid) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribe(new Consumer<BluetoothSocket>() { @Override public void accept(BluetoothSocket socket) throws Exception { // Connected to the device, do anything with the socket Log.e("connectToDevice()","Start of Connection."); } }, new Consumer<Throwable>() { @Override public void accept(Throwable throwable) throws Exception { Log.e("connectToDevice()",throwable.getMessage()); } }); }

connect exception

when bluetoothSocket.connect();
log:
getBluetoothService() called with no BluetoothManagerCallback
java.io.IOException: read failed, socket might closed or timeout, read ret: -1

Add Wrapper Method For enable()

In an Android mobile device scenario, we should use enableBluetooth() on RxBluetooth, which works nicely. However, in an Android Things environment, that's not an option: the enable-Bluetooth activity doesn't even exist.

On an Android Thing, we're supposed to use enable() directly. However, RxBluetooth doesn't wrap that method, so we have to get our own BluetoothAdapter for that. This isn't a huge issue, but since you have other pass-through wrapper methods (e.g., isEnabled()), it would be handy if you offered an RxBluetooth wrapper for enable() (and perhaps disable()).

If you'd like me to make this change and send you a pull request, just let me know.

Thanks for considering this!

observeByteStream() Subscriber not cancelled

Disposing observeStringStream() doesnot cancel the subscriber from observeByteStream() causing exception when trying to close connection.

Caused by: com.github.ivbaranov.rxbluetooth.exceptions.ConnectionClosedException: Can't read stream.

Start reading string stream:
Disposable disposable = mBluetoothConnection.observeStringStream() .subscribeOn(Schedulers.computation()) .subscribe(s -> Log.e("Data", s));

Stop reading stream:
disposable.dispose()

Call
bluetooth.closeConnection()

Never cancels subscriber and throws exception
Class BluetoothConnection.java

public Flowable<Byte> observeByteStream() {
    if (observeInputStream == null) {
      observeInputStream = Flowable.create(new FlowableOnSubscribe<Byte>() {
        @Override public void subscribe(final FlowableEmitter<Byte> subscriber) {
          while (!subscriber.isCancelled()) {
            try {
              subscriber.onNext((byte) inputStream.read());
            } catch (IOException e) {
              connected = false;
              **subscriber.onError(new ConnectionClosedException("Can't read stream", e));**
            } finally {
              if (!connected) {
                closeConnection();
              }
            }
          }
        }
      }, BackpressureStrategy.BUFFER).share();
    }
    return observeInputStream;
  }

Using lib from android service

Hi,

I plan to use your RxBluetooth lib from an android service (called with startService, ie: long running service) to continuously talk to connected devices.

I think I can pass a Service.this to the RxBluetooth constructor as Android services inherit from Context.

However I can see a unsubscribeInUiThread call (which depends on AndroidSchedulers) that may cause trouble as the RxBluetooth methods will be called from the service code.

Do you have any suggestion on how to deal with limitation and make the lib available on service side ?

Thanks a lot!

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.