• Hello,
    I'm trying to get Espruino to store a timestamp in Storage, and the read from it on boot and set the current time accordingly. This is the salient code:

    var TimeController = {
      currentTimeFilename: "currentTime",
      writeCurrentTime: function() {
        var currentTime = Number(new Date(Date.now()).getTime() / 1000);
        Storage.writeJSON(this.currentTimeFilena­me, {
          "timestamp": currentTime,
        });
      },
      readCurrentTime: function() {
        var currentTime = Storage.readJSON(this.currentTimeFilenam­e, true);
         if (currentTime) {
           setTime(currentTime.timestamp);
        }
      },
    };
    
    E.on('init', function() {
      clearInterval();
      clearTimeout();
      clearWatch();
      TimeController.readCurrentTime();
      setInterval(() => {
        TimeController.writeCurrentTime();
      }, 30000);
    });
    
    save();
    

    However, when the code executes the first time after Espruino is plugged into power (not PC), all of the intervals fire incredibly rapidly (similarly to issue described here). Removing all instances of setTime remedies this. Not sure what kind of conflict is occurring there, any help would be appreciated!

About

Avatar for Levon @Levon started