• This seems pretty basic.

    If I save a "program" to flash, will it execute again to reload the functions and watches if the battery is changed?


    var presses = 0;
    setWatch(function() {
        0x1811 : [presses],
        0x180F : [E.getBattery()],
        0x1809 : [Math.round(E.getTemperature())]
    }, BTN, { edge:"rising", repeat:true, debounce:25 });
    // Interval to update advertising values
    setInterval(function() {
        0x1811 : [presses],
        0x180F : [E.getBattery()],
        0x1809 : [Math.round(E.getTemperature())]
    }, 30000);    // 30 sec
    function startFlashing(pin, period) {
      var on = false;
      flashingLedInterval = setInterval(function() {
        on = !on;
        digitalWrite(pin, on);
      }, period);
    function stopFlashing(pin) {
      digitalWrite(pin, off);
  • p.s. I have done both a) most of the logic/programming/timers in the puck.js code and b) the logic/program/timers in Node-Red.

    This code version is where nearly all of the logic is one in Node-Red.

    can make a new thread if it gets meaty. Pros/cons?

  • Henry, a good/save/robust practice is to have an onInit() { ... } function that gets everything going on power cycle... Having active code - in level 0 - is executed on upload and can be challenging. Take a look at simple explanation how to save code that espruino run on start?.

    Furthermore, below things give me a bit the chill... because this can actually mess with the Espruino platform which may already include running JS (boot code that uses watches, and timers). To avoid having to go with the crow bar but still want to be able to 'cleanup after me-code' or have in the application the need to stop or pause these hw and sw events/hooks, ,I use variables to hold on to the watch, timeout and interval handles and then use them in the clear functions.


    What code distribution topology to chose? ...it all depends. The pendulum is always swinging and a hybrid approach feels to me right. Question is: what and where are 'your' pain points? There is allways pain - never no pain - but minimizing it by optimizing is the virtue.

  • If I save a "program" to flash, will it execute again to reload the functions and watches if the battery is changed?

    Yes, if you upload this code to flash via WebIDE it is permanently saved in Storage as ".bootcde" file and gets executed from top to bottom at boot time. If this suits you, it is as simple as that, you don't need anything else.

  • Not sure, but this might help give some explanation of what happens: http://www.espruino.com/Saving

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Silly question, saving to make sure it restarts after power cycle or reset.

Posted by Avatar for HeneryH_(Henery_Hawk) @HeneryH_(Henery_Hawk)