I guess there is a better way: Do not create new timer every 1000ms, but only once. Just to quote one function:
//get wifi status every second
function iw1() {
wifi_stat = Wifi.getDetails().status;
//set led blink rate
if(wifi_stat !== "connected") {led_speed = 100;}
else {led_speed=500;}
setTimeout(iw1,1000);
}
iw1();
And how to do it better:
//get wifi status every second
function iw1() {
wifi_stat = Wifi.getDetails().status;
//set led blink rate
if(wifi_stat !== "connected") {led_speed = 100;}
else {led_speed=500;}
}
iw1();
setInterval(iw1,1000);
While there is a garbage collection, it might be called too late, or not working properly - I didn't look into it. But if you call setTimeout every 1000ms instead of setInterval once there's a really high chance it'll allocate a new block of memory for a new timer every 1000ms.
The other functions shall be modified accordingly.
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.
I guess there is a better way: Do not create new timer every 1000ms, but only once. Just to quote one function:
And how to do it better:
While there is a garbage collection, it might be called too late, or not working properly - I didn't look into it. But if you call setTimeout every 1000ms instead of setInterval once there's a really high chance it'll allocate a new block of memory for a new timer every 1000ms.
The other functions shall be modified accordingly.