Sleep time and external interrrupts

  • I have a sensor to count events (rain sensor). This sensor uses sleeps mode to save power. Any event triggers an external interrupt to wake up the sensor and increment the counter. After an certain time the sensor should send the counter value to the controller.
    I use int8_t sleep(int interrupt, int mode, unsigned long ms=0); to wake up either from external IRQ or timer. But if many events occure, the timer never triggers (and the sensor does not send values to controller).
    Is it possible to get the elapsed sleep time, when external IRQ triggers? Then I can calculate/estimate when it's time to send values to controller.

  • Mod

    Are you referring when the sensor is wet and not reporting anything?

  • No, I have something like this, but try to get it battery powered.
    It generates a pulse after a certain amount of rain.

  • Mod

    If it is a tipping bucket if you are receiving too many pulses you either have a bucket too small or you really have a storm raging outside 😀

  • Mod

    @karlheinz2000 if you want to know the time elapsed while sleeping you either need a rtc or you need to ask another node (or the controller) about time. See "Fetching time from controller" at

    No timers are active during sleep.

  • Is it possible to read ms from

    void hwInternalSleep(unsigned long ms)
    	// Let serial prints finish (debug, log etc)
    	while (!interruptWakeUp() && ms >= 8000) {
    		ms -= 8000;

    mySleepTime - ms , should be the elapsed sleep time?!

  • Mod

    Unfortunately there is no support for getting ms from hwInternalSleep but I guess the function could be modified. I like the idea. It wouldn't be able to account for time spent when woken up by interrupt, but that error would be max 8 seconds (on atmega328) which would be good enough for many applications.

  • @mfalkvidd any idea for a (quick and dirty:sunglasses: ) workaround? Just copy ms in hwInternalSleepin some global variable? Or will this not work? I'm more in hardware than software...

  • Mod

    @karlheinz2000 a global variable should work. Quick and dirty :grimacing:
    Make sure to name it something unique.

Log in to reply

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.