Probably the best idea is to use the hardware watchdog - that's what they have them built in for: https://www.espruino.com/Reference#l_E_enableWatchdog
So:
E.enableWatchdog(10, false); setInterval(function() { // your code here E.kickWatchdog(); }, 2000);
If the function doesn't complete to the point that kickWatchdog is called, the whole device will restart.
kickWatchdog
But you might also want to look at https://www.espruino.com/Debugger#debugging-when-not-connected - at least then when it stops working you can maybe connect and get some idea what happened?
@Gordon started
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.
Probably the best idea is to use the hardware watchdog - that's what they have them built in for: https://www.espruino.com/Reference#l_E_enableWatchdog
So:
If the function doesn't complete to the point that
kickWatchdog
is called, the whole device will restart.But you might also want to look at https://www.espruino.com/Debugger#debugging-when-not-connected - at least then when it stops working you can maybe connect and get some idea what happened?