I'm trying to find the most effective way (in terms of power consumption) to do the following:
- - I have an input signal that goes high for a couple of seconds when an event is detected
- initially, the ESP32 should have a state set to "inactive"
- when the input signal goes high:- - if inactive: the ESP32 should be woken up, set the state to active, send a message, set a timer (say, 5 minutes), then go back to sleep
- if already active, the timer should be reset (cancelled and re-armed at 5 minutes)
- - if inactive: the ESP32 should be woken up, set the state to active, send a message, set a timer (say, 5 minutes), then go back to sleep
The goal is to have one message sent out when "activity" starts, and another one when there has been no activity for a given time (5 minutes here). Average power consumption should be as low as possible. The input signal will usually have long periods (hours) of either staying low all the time, or going up/low many many times. I don't want to send a message any time the input signal goes high, and would like to avoid waking up to ESP32 every time.
Input signal:
Code: Select all
________-__-_____-_-_-_-____-____________________
| |----timer----|
Active message Inactive message
Another option would be use the ESP32 wake stubs to do the minimal work required when the signal goes high (check a flag, reset timer) and go back to sleep immediately, but I have no idea how long that takes nor how much power it would draw. From what I understand, the wake stub happens very early and skips a lot of the initialisation, so it should be relatively quick and draw limited current, but I have no idea how quick and how much.
So, here are the questions:
- Is there a way to stop the ULP and wake it up (but not the ESP32 cores) on interrupt?
- How much time and power would a minimal wake stub take?
- Is there another alternative?
Thanks!