• Regarding starting of your code on power-up, add to you code (in the IDE editor / right page) either

    function onInit() {
       ...
    }
    

    or

    E.on("init", function(){
       ...
    });
    

    and then upload the code and finally issue a save(); command in the console (left pane in IDE). For more details, see reference E on event and onInit().

    Personally, I prefer the single function onInti(){ ... }, because at development time, I just can either add as very last line in the code for invocation onInit(); which invokes it automatically on (after) every upload, or invoke it manually by entering onInit(); in the console.

    Furthermore, E.on("init", function(){ ... }); has major restriction, because sequence is not fully controllable nor the timing:

    • If initialization code has to run in a certain sequence - different from loading or appearance sequence of a module (which would contain E.on("init",...); to init itself but with dependencies on other modules), initialization may happen with wrong settings.
    • If initialization is asynchronous / callback oriented (next initialization is required to wait until callback is issued), initialization may happen too early.

    To handle configuration, initialization (w/ sequencing/callbacks), and later sequencing / callbacks, I created a gCtl (globalController), with more about the global controller vs. E.on("init",...) and a [Tasker (kind of a Promise] with built-in retry options)[http://forum.espruino.com/conversations/­261352/].

About

Avatar for allObjects @allObjects started