I have a strange issue where a button handler will work fine for hours / days, but then suddenly stop working. I know the button itself is fine - a separate periodic timer reads the button status correctly.
My device uses auto light sleep.
the handler is set in js using the following function:
GPIO.set_button_handler(
b_P,
GPIO.PULL_UP,
GPIO.INT_EDGE_ANY,
50,
function (b_P) {
let button_State = GPIO.read(b_P);
if (button_State === BTN_PRESS) {
li("Button Pressed");
if (isProvisioning === true) {
// li("Button press:" + js(button_State));
Timer.del(timer_DeepSleep);
timer_DeepSleep = Timer.set(5000, 0, checkButtonDeepSleep, null);
} else {
timer_btnRelease = Timer.set(
100,
0,
function () {
Timer.del(timer_btnRelease);
Timer.del(timer_Provision);
timer_Provision = Timer.set(8000, 0, checkButtonProvision, null);
boxButtonHandler(b_P);
},
null
);
}
} else {
li("Button Released");
Timer.del(timer_Provision);
let f = ffi("void blink_watchdog()");
f();
}
// // }
// }
},
null
);
What’s even stranger is that, for testing purposes I created an RPC function to create a new handler:
RPC.addHandler("checkButton", function () {
// GPIO.disable_int(b_P);
GPIO.set_mode(b_P, GPIO.MODE_INPUT);
li("Setting new interrupt handler on: " + js(b_P));
let res = GPIO.set_int_handler(b_P, GPIO.INT_EDGE_ANY, function(pin) {
let button_State = GPIO.read(pin);
if (button_State === BTN_PRESS) {
li("Button Pressed (3)");
} else {
li("Button Released (3)");
}
}, null);
GPIO.enable_int(b_P);
return res
});
If I call the above function when the button is still working, as expected the original handler gets replaced by this new one, and all works fine. However, once the original handler fails, even if I then call this function, it returns 1 (so success), but it doesn’t work either - no response at all when the button is pressed.
The button is on GPIO 13. I have a separate button handler on GPIO 33 which continues to work fine, and has never failed.
Anyone got any ideas what could be causing this / how to resolve it?