I've actually got it working now, although I'm still not sure what I changed. I stripped out pretty much everything, rewrote, and then rigged it so on('disconnect') executes NRF.sleep()... the idea being that when the Puck disconnects (for whatever reason), it won't reconnect until manually woken by a keypress.
I don't mess with advertising or services beyond the initial setup, which unfortunately loses the battery monitor; however, that doesn't seem to make much difference anyway: the device is either connected (no advertising?) or disconnected and sleeping (no advertising)
I'm also not sure what the drain on this is. Next I'll have to rig it up to test power consumption while sleeping, as that's the ultimate aim. I also have to solve the auto-switch-off that triggered this whole matter in the first place; I'm hoping it's just a case of setTimeout(...NRF.disconnect()..., 1000*60*10) ... clearTimeout().
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.
Another day, another rewrite :)
I've actually got it working now, although I'm still not sure what I changed. I stripped out pretty much everything, rewrote, and then rigged it so
on('disconnect')
executesNRF.sleep()
... the idea being that when the Puck disconnects (for whatever reason), it won't reconnect until manually woken by a keypress.I don't mess with advertising or services beyond the initial setup, which unfortunately loses the battery monitor; however, that doesn't seem to make much difference anyway: the device is either connected (no advertising?) or disconnected and sleeping (no advertising)
I'm also not sure what the drain on this is. Next I'll have to rig it up to test power consumption while sleeping, as that's the ultimate aim. I also have to solve the auto-switch-off that triggered this whole matter in the first place; I'm hoping it's just a case of
setTimeout(...NRF.disconnect()..., 1000*60*10) ... clearTimeout()
.For the benefit of anyone else attempting this - https://gist.github.com/tomgidden/875b5a5522deeabd9d1ef389607e434a :
(updated with auto-sleep)