Hi there,
Adding the cloud iot layer now to my whole arduino knowledge. That's very interesting. Fast. Easy.
Something (many things actually) are still cryptic.
In my code, I often use a condition in order to measure my physical values only each 1000ms for instance. Works well.
But, how this "timer" (which I know is not a proper timer in the hardware sense) deals with the arduino update routine?
Two clocks, = things not sync.
If I have my "timer" at 1000ms. Each measure update a variable each 1000ms.
If my arduino update for that variable is 2000ms, for sure the "timers" won't be synced.
How do you deal with that? Or shouldn't I deal with that?
I wrote this post as I feel if I remove my "timer", my live chart on my dashboard seems to update perfectly, if I put it, it doesn't seem to do that.
You should have only one timer in the system, not two. So you have two options:
Do not implement any timing logic in your code, and just keep the variable continuously up-to-date (possibly in every single loop). Then, set the update policy of the IoT Cloud variable to "update every X seconds". This approach lets you keep your code simple and clean, but it may not work when your sensor needs to be polled at intervals anyway.
Implement your own timing logic in your code and set the update policy of the IoT Cloud variable to "update on change". This way, the new value will be propagated to the cloud as soon as you assign it to the variable. This approach is good whenever you need to implement a timing logic manually not only to decide when to send the value to the cloud but also to set the intervals at which your sensor is polled.
Mixing the two approaches (i.e. implementing your own timing logic + telling IoT Cloud to update the value "every X seconds") will not work properly because, as you described, you'll have two timers that will not be aligned.
don't want to use the delay() to lock the code, but I know, sometimes, reading the sensor at the loop rate shouldn't be done. This is for the 1. you mentioned.
aligning timers/clocks is something we know well at https://structure-void.com... we used to code c++ stuff, max/msp too, mainly for sounds/sequencing/visuals works. this was what I sensed here.
I'll also smooth my measurement routine too as some temperature measures seem to oscillate a bit around a mean.