How to get time a sensor has slept
-
I would like to use sleep function with wakeup from interrupt or timeout. The function only returns the wakeup reason. Is there a possibility to get the time slept when the wakup came from interrupt? The reason is that I would like to process the inteerupt an then recall the sleep with only th remsing time from the inital sleep time.
-
@Heizelmann almost all Arduinos stop all timers when sleeping (because timers need power), so it is not possible for the mcu to know how much time it has slept.
There are a few tricks though. See these threads and see if any of the suggested solutions would work for you.
https://forum.mysensors.org/post/71715
https://forum.mysensors.org/topic/5284/sleep-time-is-not-actual-sleep-time/
https://forum.mysensors.org/topic/6837/sleep-time-accuracy/
https://forum.mysensors.org/topic/7216/test-time-with-timeawaresensor-sketch/
-
I think the most simple solution is to use an RTC. For example DS1302, it uses little power and runs at low voltage which is great for battery powered sensors. Precision is also good enough if you are not sleeping for days.
-
Or use the Nrf5 which can keep time while sleeping
-
If your Mysensors gateway is reporting to a domoticz server (or other system which supports it), you can request the present time from the controller, before and after sleeping, as indicated here:
https://www.mysensors.org/download/sensor_api_20#requesting-data
-
@mfalkvidd said in How to get time a sensor has slept:
There are a few tricks though. See these threads and see if any of the suggested solutions would work for you.
https://forum.mysensors.org/post/71715That is exact the same issue .Thanks for pointing to this. I didn't found this.
-
I'm not sure if I really understood the problem, but also have several nodes with interrupt-bases actions (like motion).
Isn't the easiest way to get around that kind of problems to not use the sleep-with-interrupt-funcionality but a seperate ISR instead? Like the Water Meter Pulse Sensor example?
In case remaining sleep time could be too long (eg. for wind alerts), also adding (conditioned) sending functionality to an ISR is possible.
-
@rejoe2 For battery power saving you need sleep().
-
@Heizelmann My answer also presumed using sleep() in the main loop, but to combine it with a seperate ISR. This concept seems to work, at least this was my conclusion when reading the mentioned PulseCounter-sketch, that can be configured as sleeping or non-sleeping node.
But I may be wrong, all my nodes are on power supplies until now...