-
• #2
Think I solved the problem by calling clearWatch(). Will keep you posted.
-
• #3
I'd imagine the issue is:
var now = getTime(); var pulsetime = now - lastpulse;
If this gets called twice in quick succession then the second time it's called you'll get a very small time period reported.
setWatch
does actually have an option calleddebounce
that will automatically discount any spikes off less than the given length in milliseconds, so you could try that -
• #4
Thanks. That worked too. I had written a workaround to say if the reading was too small then skip. But denounce:20 accomplishes the same thing. Thank you.
I've tried creating an electric pulse meter with the puck js 2.1 The code works on occasion but then starts reporting funny values for watts. The general idea of the code is to get the current time, compare it with the previous time of the last pulse and use the time difference to calculate the watts. Sometimes however, even though i can tell from the logs that say the last pulse time was 12 or so seconds ago, the calculation only reads .01 of a second therefore throwing the calculation off. It's not consistent, sometimes it gets it bang on, other times not. For instance I ran it yesterday for the first time, it seem to run fine for a few hours but then started reporting erroneous values. When i ran updated code 10 minutes ago with better logging, i can see that every second reading is correct. Note originally i was using Date.now() for the time, but then tried getTime() to see if it would fix the issue, but it did not. Please see logs and code below.
Here are the logs