Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending the list of commands to device using RxAndroidBle #27

Closed
DKKovalev opened this issue Jun 3, 2016 · 7 comments
Closed

Sending the list of commands to device using RxAndroidBle #27

DKKovalev opened this issue Jun 3, 2016 · 7 comments
Labels
question / library Issue containing question / discussion about library workings

Comments

@DKKovalev
Copy link

Summary


Hi, i'm trying to connect and send the list of commands, consisting of 16 bytes to BleDevice. How can i do this properly?
p.s. I'm pretty new to JavaRx

@ardmn
Copy link

ardmn commented Jun 3, 2016

It is topical issue for me too. With Every connecting to ble device i need send "start" commnad and after that i can send next commands. In my case the ble device store some data for 7 days . To obtain the all data for one day I need send 3 commands. Therefore to get the data in the last 7 days, need to send a list of 21 (+ start command). Please can you give advice how solve this problem ? May be you know nice solution for commands queue that can easily integrated with rxAndroidBle lib? Thanks.

@dariuszseweryn dariuszseweryn added the question / library Issue containing question / discussion about library workings label Jun 6, 2016
@uKL
Copy link
Collaborator

uKL commented Jun 16, 2016

I'm not sure if I get it correctly. Are you trying to write some data to a characteristic in a given order? If yes, you can just flatMap write operations and the order will be preserved.

@uKL
Copy link
Collaborator

uKL commented Jun 20, 2016

@DKKovalev @ardmn Could you follow up?

@ardmn
Copy link

ardmn commented Jun 20, 2016

Sorry, @uKL I will try it tomorrow :)

@KolinLoures
Copy link

KolinLoures commented Jun 28, 2016

@uKL Hi. I tried to find answer to this issue, but it still not work. May you give some helpful advice if it is not difficult for you :)

public void startWriteCommucation(final ArrayList<byte[]> b) {
        if (isConnected()){
                connectionObservable
                        .flatMap(new Func1<RxBleConnection, Observable<Observable<byte[]>>>() {
                            @Override
                            public Observable<Observable<byte[]>> call(RxBleConnection rxBleConnection) {
                                final List<Observable<byte[]>> list = new ArrayList<>();
                                for (byte[]  bytes: b){
                                    Log.e("MyTag", Arrays.toString(bytes));
                                    list.add(rxBleConnection.writeCharacteristic(BleDevice.characteristicWrite, bytes));
                                }
                                return Observable.from(list);
                            }
                        })
                        .flatMap(new Func1<Observable<byte[]>, Observable<byte[]>>() {
                            @Override
                            public Observable<byte[]> call(Observable<byte[]> observable) {
                                return observable;
                            }
                        })
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(
                                new Action1<byte[]>() {
                                    @Override
                                    public void call(byte[] bytes) {
                                        Log.e("MyTag2", Arrays.toString(bytes));
                                        view.setTextStatus("WRITE SUCCESS");
                                    }
                                },
                                new Action1<Throwable>() {
                                    @Override
                                    public void call(Throwable throwable) {
                                        view.setTextStatus("!!!FAIL WRITE!!!");
                                        throwable.printStackTrace();
                                    }
                                }
                        );
            }
    }

This code works, and writes that it was successfull, but device does't responed.

@dariuszseweryn
Copy link
Owner

I think this question should go to www.stackoverflow.com with #rxandroidble
If I understood you correctly - you just want to perform some data exchange between the device and the app before something else will happen. In this situation you can write your own connecting function like:

public Observable<RxBleConnection> establishConnectionToMySpecificDevice(RxBleDevice device) {
  return rxBleDevice.establishConnection(this, false)
    .flatMap(rxBleConnection ->
        rxBleConnection.writeCharacteristic(uuid, bytes)
        .flatMap(bytes -> rxBleConnection.readCharacteristic(uuid))
        .map(bytes1 -> /*do something with read bytes*/ rxBleConnection)
    );
}

And use it wherever you need in the code?

@KolinLoures
Copy link

KolinLoures commented Jul 8, 2016

dariuszseweryn added a commit that referenced this issue Jul 11, 2016
…() with the same characteristic would overwrite BluetoothGattCharacteristic.value

Summary: Related to: #27 and http://stackoverflow.com/questions/38250610/sending-the-list-of-commands-to-device-using-rxandroidble-rxjava/

Reviewers: michal.zielinski, pawel.urban

Reviewed By: michal.zielinski, pawel.urban

Differential Revision: https://phabricator.polidea.com/D1692
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question / library Issue containing question / discussion about library workings
Projects
None yet
Development

No branches or pull requests

5 participants