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

Question about write reliability / 'resend' mechanism if package was lost. #295

Open
andresbrocco opened this issue Feb 17, 2023 · 1 comment

Comments

@andresbrocco
Copy link

I'm controlling a peripheral by writing to certain characteristics at a rate of 5 Hz. Those characteristics are 'writable' and not 'writable without response'.

  1. What happens to the adapter if no response is received (for example if a package is lost)
  • Does the adapter hang? (I mean, it gets busy and unable to send other messages)
  • Is there a timeout?
  • Does the callback get called with an 'error'? (I've tested and that seems not true)
  1. Ideally if no answer is received (in 50ms, for example), I would try and re-send the previous message. How could I implement that behaviour?

Example:

characteristic.write(data, false, async (error) => {
    if (error) {
        < I would try to re-send the same data here >
    } else {
        < everything went fine >
    }
});

In my example code I'm not sure where/how could I implement a 'resend' mechanism if the callback is never called when no response is received.

I thought about using Promise.any() like the following:

Promise.any([characteristic.writeAsync(data, false),
             new Promise((resolve, reject) => { setTimeout(() => reject(new Error('timeout')), 20) })]
).then(() => {
    < everything went fine >
}).catch((error) => {
    < try to re-send the data >
});

But that does not seem to work either...

  1. Am I in a good direction? Or are there any better solutions to that simple problem of ensuring the delivery of a package?

I would be grateful for any light on my problem!

@andresbrocco
Copy link
Author

I was supposed to use Promise.race() instead of Promise.any(), now it's working... But that doesn't answer the question 1).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant