Interrupted sleep

I have a sketch for a battery powered node that sleeps a certain amount of time, let's say 2 minutes. unsigned long SLEEP_TIME = 120000; // Wait time between reads (in milliseconds) When it wakes up, it will check a few sensors and report new values (if any) to the gateway. So far so good.

However (there's always a but, isn't there?), the 2 minute sleep is allowed to be interrupted by the change of a pin. That pin is connected to a rain meter. Measuring the rain must be done instantly.

Every time that the loop() function runs, other sensors are checked.

That's OK if it rains normally but sometimes it rains like h*ll. I'm concerned that the rain meter will be tripped so frequently that there is no time to check other sensors and report them to the gateway.

I'm useless when it comes to explain things. But I'd like the rain sensor to report whenever the rain sensor is tripped. I would like the other sensors to report at the 2 minutes interval regardless of the rain sensor. As it is now, every time the rain sensor interrupts the sleep, all sensors gets checked. I would like it to report the rain and go back to sleep the REMAINING SLEEP TIME. I understand if my explanation is beyond what ca be understood (it's worse than Kurt Olsson) so I add the source below:

@mfalkvidd Thanks a lot for your suggestion. I will think this through during the day. It might still be problems due to the dynamic nature of the rain.

It would be hard for me to define a reasonable good value for MAX_NUMBER_OF_TRIPS_WITHOUT_SENSOR_REPORT when rain in the interval ranging from 11 mm per hour up to maybe as much as 240 mm per hour (extreme but not impossible) would disrupt the readings of other sensors.

I also have a doubt that my sketch will work well in a case where the Arduino is already awake (handling other sensors) when the rain bucket tips. It's just a guess but I believe that the tipping will not be counted at all in such a scenario.

What do you think? If so my sketch is badly designed (only myself to blame) and maybe I should consider giving the rain gauge it's own Arduino board. It would make things much cleaner. What do you think?

I had the same issue some time ago, measuring time while asleep and running on batteries. I ended up building this project: Battery operated rain gauge..
The time between reports is controlled by a CMOS 555 timer, independently from the Arduino. Needless to say I did not include any other sensors.

@berkseo the troubling case (without rtc) is if the node sleeps let’s say 30 minutes and the rain causes an interruppt every 1-29 minutes. In that case, sleep will always return woken up by interrupt. If the rain keep like this for 5 hours, the other sensors will not be activated.

@mfalkvidd
In my previous post, I rather answered @yveaux's question, but I didn't fully understand what @yveaux was paying attention to ... interrupts. An example from the RTC will not work with regular interruptions. No examples of sleep time tracking will work. As for this topic, Your version is the solution. I can also offer a solution below. If it suddenly started to rain then change the sleep mode, do without interruption for the next 2 minutes. In the next 2 minutes, it doesn't matter if rain ends or continues. Here, the subtle point is only that in the worst case (for example, the rain went on 119 seconds) the interval between the data will be 4 minutes.