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)
2) 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...
3) Am I in a good direction? Or are there any better solutions to that simple problem of ensuring the delivery of a package?
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)
2) 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:
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:
But that does not seem to work either...
3) 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!