Putting all you code into onInit() is a good start. More later about that.
Unfortunately then calling onInit() in the upload 'JS thread' defeats this precaution...
Replace the onInit(); with setTimeout(onInit,999);. This allows the 'upload JS thread' to finish, restore usual console connection, and start your code.
You still may run into issues if there is too much in onInit();. Having all your function definitions 'in root' individually is better in regard of memory and buffer consumption spikes.
Only the startup of your code - especially when it deals with communication - has to be in the onInit() and putting it into a setTimeout() for the time of development makes it work.
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.
Putting all you code into
onInit()
is a good start. More later about that.Unfortunately then calling
onInit()
in the upload 'JS thread' defeats this precaution...Replace the
onInit();
withsetTimeout(onInit,999);
. This allows the 'upload JS thread' to finish, restore usual console connection, and start your code.You still may run into issues if there is too much in
onInit();
. Having all your function definitions 'in root' individually is better in regard of memory and buffer consumption spikes.Only the startup of your code - especially when it deals with communication - has to be in the
onInit()
and putting it into asetTimeout()
for the time of development makes it work.I'm sure you read simple explanation how to save code that espruino run on start?. (Even though Epruino has now more options to overcome issues of that sort of, the core has not chanted at all and is still very applicable.)
Looking forward to hear from you! - ao