setTimeout big issue - Puck.js at 2.04 #3386
Replies: 13 comments
-
|
Posted at 2020-05-25 by SergeP I've just checked that getTime() works correctly at the same time. |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2020-05-25 by SergeP I have checked the same on cleaned Puck.js. And it works. So I will try to find when it happens. |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2020-05-25 by SergeP At my greenhouse system it does not work. I see something like this: SetTimeout is only a part of code in dump, of course. But I add the timeout manually from console, so other code do not interact with the timeout. |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2020-05-26 by @gfwilliams That's really odd - so you're saying that the timeout value reported in If you're waiting 'a few minutes' then 6869723.54125976562-6712184.47875976562=157539.06249999906 - so 160ish seconds, which sounds about right. By contrast, Honestly I'm not too sure what could be the issue here. As far as I know nothing has changed in the setTimeout code in years. Is there any way you could start pulling code out of your greenhouse controller until you can get it down to a level that I could look at it and reproduce it? |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2020-05-26 by SergeP 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. Upd: I can not upload file (do not know why) so code is below: |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2020-05-27 by @gfwilliams Thanks for stripping this down... I just stripped it right back and there's no problem. It turns out the issue is how timers are handled when a timer is added within a timer callback. Try this: LED1 should flash every second. However if you press BTN1 it'll just stop! I've filed an issue for this at espruino/Espruino#1829 and I'll try and get it fixed ASAP. However you could fix it as-is by removing your |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2020-05-27 by @allObjects
...ooops... I used that all over the place... not just for timing, also for 'breaking the JS thread'... - so have to go back and validate... (for example SW Button... etc.) |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2020-05-27 by SergeP
It's just to make an update of full BLE advertizing, while there are many calls of updateAdv in many functions. So I can call updateAdv in every place where I change some part of advertizing data but actually I have only one update where all these fields are changed. It is update aggregator. |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2020-05-27 by SergeP Yes. The stripped version works when I remove the setTimeout. But my full version is based on Timeouts from Timeouts from Timeouts etc... Usually I do not ever know if some function is called from timeout or not. |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2020-05-27 by @gfwilliams
Sadly with 2vxx (and maybe earlier) it seems that you can end up with your timeouts not being called on time. You could use events instead of But I actually just fixed this - so in 2v06 when released (or a cutting edge build) you'll be fine |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2020-05-27 by SergeP I've got cutting edge v2.05.107 and it looks like working! Wow! |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2020-05-28 by SergeP It works! Wonderful! Thank you, @gfwilliams! |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2020-05-29 by @gfwilliams Great! As for OneWire, I'm surprised there is any difference as I didn't think much changed there. But basically the issue is that you're always meant to give the Bluetooth stack priority. I think at some point in the past I was disabling it for OneWire, and that made Espruino unstable and it could spontaneously reboot. I decided it was better to just have OneWire fail every so often (which is easy to recover from) rather than to have a reboot :) I looked just now and there may be a hacky solution: espruino/Espruino#1831 However you're using OneWire for a DS18B20? http://www.espruino.com/DS18B20 If so you can just do: Note that you may also need to do similar stuff at boot time (when you're finding the address of the OneWire sensor to use) as occasionally it may not find it. Or... you could use |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2020-05-25 by SergeP
I still try to update my greenhouse controller. It worked at v1.92 and now it is with 2.04
I've found that it begins planned sequences at incorrect time. Fully incorrect. I've just made the check:
I've started a few setTimeouts, get dump(), then have disconnected, have waited about 10 or 12 minutes and get dump() again.
Here is the results of first dump()
And second one
As you can calculate, Puck.js thinks that I was away only about 1 or 2 minutes.
That is really problem for my greenhouse.
Is it a major bug or new feature (may be some kind of deepsleep which I should turn off)?
Beta Was this translation helpful? Give feedback.
All reactions