RxAndroidBle: JustWorks bonding and operation timeout issue












0















I am dealing with characteristics that need encryption, so Android will automatically create a bond to perform the write/read operations.




There is a possibility that a bond will be automatically created by
the OS. This usually happens when a read/write request is sent to a
characteristic that needs encryption. (reference here)




However, the first read/write operation will fail with a timeout (the default in the library is 30 seconds), but if I retry the operation immediately after it works because the bond was created.



I know that the first read/write operation will always fail because of the bonding thing, so I want to perform it as quickly as possible, and not wait for 30 seconds to fail. In order to do that, what I did was to establish a 10 seconds timeout for the whole connection like this:



scaleDevice.establishConnection(false, new Timeout(10, TimeUnit.SECONDS))



However, I would like to be able to change the operation timeout after establishing the connection, so I can do the following:




  1. Establish the connection with the default 30 seconds operation timeout.

  2. Before I need to read/write for the first time to an encrypted characteristic, I want to set the timeout to a small value (maybe 5 seconds).

  3. The first read/write operation to the encrypted characteristic will fail after 5 seconds.

  4. I will retry the operation and now it will succeed.

  5. I want to set the operation timeout back to 30s.


Is that possible in the current version of the RxAndroidBle library?










share|improve this question





























    0















    I am dealing with characteristics that need encryption, so Android will automatically create a bond to perform the write/read operations.




    There is a possibility that a bond will be automatically created by
    the OS. This usually happens when a read/write request is sent to a
    characteristic that needs encryption. (reference here)




    However, the first read/write operation will fail with a timeout (the default in the library is 30 seconds), but if I retry the operation immediately after it works because the bond was created.



    I know that the first read/write operation will always fail because of the bonding thing, so I want to perform it as quickly as possible, and not wait for 30 seconds to fail. In order to do that, what I did was to establish a 10 seconds timeout for the whole connection like this:



    scaleDevice.establishConnection(false, new Timeout(10, TimeUnit.SECONDS))



    However, I would like to be able to change the operation timeout after establishing the connection, so I can do the following:




    1. Establish the connection with the default 30 seconds operation timeout.

    2. Before I need to read/write for the first time to an encrypted characteristic, I want to set the timeout to a small value (maybe 5 seconds).

    3. The first read/write operation to the encrypted characteristic will fail after 5 seconds.

    4. I will retry the operation and now it will succeed.

    5. I want to set the operation timeout back to 30s.


    Is that possible in the current version of the RxAndroidBle library?










    share|improve this question



























      0












      0








      0








      I am dealing with characteristics that need encryption, so Android will automatically create a bond to perform the write/read operations.




      There is a possibility that a bond will be automatically created by
      the OS. This usually happens when a read/write request is sent to a
      characteristic that needs encryption. (reference here)




      However, the first read/write operation will fail with a timeout (the default in the library is 30 seconds), but if I retry the operation immediately after it works because the bond was created.



      I know that the first read/write operation will always fail because of the bonding thing, so I want to perform it as quickly as possible, and not wait for 30 seconds to fail. In order to do that, what I did was to establish a 10 seconds timeout for the whole connection like this:



      scaleDevice.establishConnection(false, new Timeout(10, TimeUnit.SECONDS))



      However, I would like to be able to change the operation timeout after establishing the connection, so I can do the following:




      1. Establish the connection with the default 30 seconds operation timeout.

      2. Before I need to read/write for the first time to an encrypted characteristic, I want to set the timeout to a small value (maybe 5 seconds).

      3. The first read/write operation to the encrypted characteristic will fail after 5 seconds.

      4. I will retry the operation and now it will succeed.

      5. I want to set the operation timeout back to 30s.


      Is that possible in the current version of the RxAndroidBle library?










      share|improve this question
















      I am dealing with characteristics that need encryption, so Android will automatically create a bond to perform the write/read operations.




      There is a possibility that a bond will be automatically created by
      the OS. This usually happens when a read/write request is sent to a
      characteristic that needs encryption. (reference here)




      However, the first read/write operation will fail with a timeout (the default in the library is 30 seconds), but if I retry the operation immediately after it works because the bond was created.



      I know that the first read/write operation will always fail because of the bonding thing, so I want to perform it as quickly as possible, and not wait for 30 seconds to fail. In order to do that, what I did was to establish a 10 seconds timeout for the whole connection like this:



      scaleDevice.establishConnection(false, new Timeout(10, TimeUnit.SECONDS))



      However, I would like to be able to change the operation timeout after establishing the connection, so I can do the following:




      1. Establish the connection with the default 30 seconds operation timeout.

      2. Before I need to read/write for the first time to an encrypted characteristic, I want to set the timeout to a small value (maybe 5 seconds).

      3. The first read/write operation to the encrypted characteristic will fail after 5 seconds.

      4. I will retry the operation and now it will succeed.

      5. I want to set the operation timeout back to 30s.


      Is that possible in the current version of the RxAndroidBle library?







      android bluetooth-lowenergy rx-android rxandroidble






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 2 '18 at 13:32







      dglozano

















      asked Nov 20 '18 at 17:38









      dglozanodglozano

      923120




      923120
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I checked the source code of the library and I realized that changing the Timeout after establishing the connection is not possible in the current version of the library.



          I opened an issue suggesting to add this functionality in the future.



          Regarding the bonding and encrypted characteristics problems, I came up with a better workaround. Instead of waiting for an automatic bonding after the first failed operation, I make sure to be bonded before establishing the connection. I achieved that by calling the bondWithDevice method available in this helper class like this:



          BondingHelper.bondWithDevice(this, scaleDevice, 30, TimeUnit.SECONDS)
          .andThen(scaleDevice.establishConnection(false))
          .observeOn(AndroidSchedulers.mainThread())
          .doFinally(this::disposeConnection)
          .subscribe(this::connectionEstablished, this::throwException);





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398556%2frxandroidble-justworks-bonding-and-operation-timeout-issue%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I checked the source code of the library and I realized that changing the Timeout after establishing the connection is not possible in the current version of the library.



            I opened an issue suggesting to add this functionality in the future.



            Regarding the bonding and encrypted characteristics problems, I came up with a better workaround. Instead of waiting for an automatic bonding after the first failed operation, I make sure to be bonded before establishing the connection. I achieved that by calling the bondWithDevice method available in this helper class like this:



            BondingHelper.bondWithDevice(this, scaleDevice, 30, TimeUnit.SECONDS)
            .andThen(scaleDevice.establishConnection(false))
            .observeOn(AndroidSchedulers.mainThread())
            .doFinally(this::disposeConnection)
            .subscribe(this::connectionEstablished, this::throwException);





            share|improve this answer




























              0














              I checked the source code of the library and I realized that changing the Timeout after establishing the connection is not possible in the current version of the library.



              I opened an issue suggesting to add this functionality in the future.



              Regarding the bonding and encrypted characteristics problems, I came up with a better workaround. Instead of waiting for an automatic bonding after the first failed operation, I make sure to be bonded before establishing the connection. I achieved that by calling the bondWithDevice method available in this helper class like this:



              BondingHelper.bondWithDevice(this, scaleDevice, 30, TimeUnit.SECONDS)
              .andThen(scaleDevice.establishConnection(false))
              .observeOn(AndroidSchedulers.mainThread())
              .doFinally(this::disposeConnection)
              .subscribe(this::connectionEstablished, this::throwException);





              share|improve this answer


























                0












                0








                0







                I checked the source code of the library and I realized that changing the Timeout after establishing the connection is not possible in the current version of the library.



                I opened an issue suggesting to add this functionality in the future.



                Regarding the bonding and encrypted characteristics problems, I came up with a better workaround. Instead of waiting for an automatic bonding after the first failed operation, I make sure to be bonded before establishing the connection. I achieved that by calling the bondWithDevice method available in this helper class like this:



                BondingHelper.bondWithDevice(this, scaleDevice, 30, TimeUnit.SECONDS)
                .andThen(scaleDevice.establishConnection(false))
                .observeOn(AndroidSchedulers.mainThread())
                .doFinally(this::disposeConnection)
                .subscribe(this::connectionEstablished, this::throwException);





                share|improve this answer













                I checked the source code of the library and I realized that changing the Timeout after establishing the connection is not possible in the current version of the library.



                I opened an issue suggesting to add this functionality in the future.



                Regarding the bonding and encrypted characteristics problems, I came up with a better workaround. Instead of waiting for an automatic bonding after the first failed operation, I make sure to be bonded before establishing the connection. I achieved that by calling the bondWithDevice method available in this helper class like this:



                BondingHelper.bondWithDevice(this, scaleDevice, 30, TimeUnit.SECONDS)
                .andThen(scaleDevice.establishConnection(false))
                .observeOn(AndroidSchedulers.mainThread())
                .doFinally(this::disposeConnection)
                .subscribe(this::connectionEstablished, this::throwException);






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 22 '18 at 6:27









                dglozanodglozano

                923120




                923120






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53398556%2frxandroidble-justworks-bonding-and-operation-timeout-issue%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    'app-layout' is not a known element: how to share Component with different Modules

                    android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                    SQL update select statement