It's hard to tell from the indenting, but it looks like maybe you could be calling setWatch multiple times? If so, it'd mean that after a few runs you're going to end up so that you press the button once, and flag is called multiple times?
One thing that could help as well - you have gattserverdisconnected but it's not being used right now. Try:
device.on('gattserverdisconnected', function() {
uart = undefined; // setting this to undefined tells us that we've disconnected
});
Then instead of just uart.disconnect(); do:
if (uart) uart.disconnect();
uart = undefined; // we already asked to disconnect
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
It's hard to tell from the indenting, but it looks like maybe you could be calling
setWatch
multiple times? If so, it'd mean that after a few runs you're going to end up so that you press the button once, andflag
is called multiple times?One thing that could help as well - you have gattserverdisconnected but it's not being used right now. Try:
Then instead of just
uart.disconnect();
do: