Right now, everything lives inside onInit(). Can you reorganize your code into separate task-focused functions? That may relieve memory issues, and also make your code more reusable on other projects.
I'd try to make onInit() focused on just the setup you need to do on power on.
You also have a long-lived nest of multiple callback functions. I'd pull the connection and sending out into a separate function that's called every 2 minutes. In that function, I'd also turn off Wi-Fi when done sending. This is good practice for IoT sensors that you intend to battery power, also.
Finally, you'll still probably have rare occasions where connection or sending fails, but these should be less frequent.
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.
Right now, everything lives inside
onInit()
. Can you reorganize your code into separate task-focused functions? That may relieve memory issues, and also make your code more reusable on other projects.I'd try to make
onInit()
focused on just the setup you need to do on power on.You also have a long-lived nest of multiple callback functions. I'd pull the connection and sending out into a separate function that's called every 2 minutes. In that function, I'd also turn off Wi-Fi when done sending. This is good practice for IoT sensors that you intend to battery power, also.
Finally, you'll still probably have rare occasions where connection or sending fails, but these should be less frequent.