• Full code of my greenhouse controller can work at standalone Puck.js. I can add it here. But it is too complex, I think. So I've cropped it. Now it is small part of code but still has the effect in setTimeout. I've just test it and results are: 1266 seconds by getTime() while only 139 with setTimeout in dump(). So the code is here. Last setTimeout is for the test.
    I've observed that it depends on setInterval (there is only one in my code) which is calles NRF.setAdvertizing(). If I remove setInterval, setTimeout looks like work correctly (I'm not sure). If I do not disconnect from device in EspruinoWebIDE It may be works correctly, too.

    Upd: I can not upload file (do not know why) so code is below:

    var Day = true;
    
    // usage types: 0 - unused, 1 - watering, 2 - anti-overheat fog
    // wateringTime is in minutes (after start), while startHour is in hours after dawn
    var channels = [
      {wateringStartedAt: 0 },
      {wateringStartedAt: 0 },
      {wateringStartedAt: 0 },
      {wateringStartedAt: 0 },
      {wateringStartedAt: 0 },
      {wateringStartedAt: 0 },
    ];
    
    
    var VArr = new Uint8Array(4);
    
    let updatePending = false;
    function updateAdv() {
      if (!updatePending) {
        updatePending = true;
        setTimeout(function () {
          updatePending = false;
          let pack = 0;
          for (let i = 0; i < channels.length; i++)
            pack = (pack << 1) + (channels[channels.length - 1 - i].wateringStartedAt ? 1 : 0);
          VArr[2] = (Day << 7) + pack;
          VArr[3] = 255;
          NRF.setAdvertising({
            0x1813: VArr
          }, {
            name: "Green", // The name of the device
            showName: true, // include full name, or nothing
            interval: 600 // Advertising interval in msec
          });
        }, 0);
      }
    }
    NRF.setTxPower(4);
    setInterval(function () {
      VArr[1] = Puck.light() * 255;
      updateAdv();
    }, 120000);
    
    
    setTimeout((s)=>console.log(s),7200000,"wwee11");
    
About

Avatar for SergeP @SergeP started