RxAndroidBle: JustWorks bonding and operation timeout issue
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:
- Establish the connection with the default 30 seconds operation timeout.
- 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).
- The first read/write operation to the encrypted characteristic will fail after 5 seconds.
- I will retry the operation and now it will succeed.
- 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
add a comment |
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:
- Establish the connection with the default 30 seconds operation timeout.
- 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).
- The first read/write operation to the encrypted characteristic will fail after 5 seconds.
- I will retry the operation and now it will succeed.
- 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
add a comment |
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:
- Establish the connection with the default 30 seconds operation timeout.
- 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).
- The first read/write operation to the encrypted characteristic will fail after 5 seconds.
- I will retry the operation and now it will succeed.
- 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
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:
- Establish the connection with the default 30 seconds operation timeout.
- 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).
- The first read/write operation to the encrypted characteristic will fail after 5 seconds.
- I will retry the operation and now it will succeed.
- 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
android bluetooth-lowenergy rx-android rxandroidble
edited Dec 2 '18 at 13:32
dglozano
asked Nov 20 '18 at 17:38
dglozanodglozano
923120
923120
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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);
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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);
add a comment |
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);
add a comment |
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);
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);
answered Nov 22 '18 at 6:27
dglozanodglozano
923120
923120
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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