You can't have code in Espruino that is called each time an advertising packet is sent, but probably the best method is just to use setTimeout?
var idleTimer;
function updateBluetooth() {
// setAdvertising...
}
function newDataPulse() {
power = ...;
updateBluetooth();
if (idleTimer) clearTimeout(idleTimer);
idleTimer = setTimeout(idleHandler, 60000);
}
function idleHandler() {
idleTimer = undefined;
power = 0;
updateBluetooth();
}
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.
You can't have code in Espruino that is called each time an advertising packet is sent, but probably the best method is just to use setTimeout?