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 useint8_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.
-
Are you referring when the sensor is wet and not reporting anything?
-
No, I have something like this https://www.mysensors.org/build/rain, but try to get it battery powered.
It generates a pulse after a certain amount of rain.
-
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
-
@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 https://www.mysensors.org/download/sensor_api_20#requesting-data
No timers are active during sleep.
-
Is it possible to read
ms
fromvoid hwInternalSleep(unsigned long ms) { // Let serial prints finish (debug, log etc) #ifndef MY_DISABLED_SERIAL MY_SERIALDEVICE.flush(); #endif while (!interruptWakeUp() && ms >= 8000) { hwPowerDown(SLEEP_8S); ms -= 8000;
?
mySleepTime - ms
, should be the elapsed sleep time?!
-
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
) workaround? Just copy
ms
inhwInternalSleep
in some global variable? Or will this not work? I'm more in hardware than software...
-
@karlheinz2000 a global variable should work. Quick and dirty
Make sure to name it something unique.
Suggested Topics
-
Arduino Celebrates 10 years (Malmö/Sweden)
Announcements • 29 Mar 2014, 17:08 • hek 29 Mar 2014, 17:08 -
Gateway without a radio
Development • 12 Jan 2025, 23:19 • OldSurferDude 14 Jan 2025, 22:07 -
Sending offset to node
Development • 20 days ago • bsl88k 15 days ago -
Gateways
Development • 6 Feb 2024, 01:16 • OldSurferDude 6 Feb 2024, 14:22 -
MQTT GW on ESP8266 supporting SSL/TLS?
Development • 4 Jun 2024, 10:21 • bgunnarb 27 Jun 2024, 13:53 -
[mysensors] Not a valid message: invalid literal for int() with base 10: '\x00\x000'
Development • 18 Sept 2024, 20:34 • kiesel 20 Sept 2024, 08:28