ESP32 - combining timer AND GPIO wake up

obod0002
Posts: 19
Joined: Sat Apr 13, 2019 2:34 pm

ESP32 - combining timer AND GPIO wake up

Postby obod0002 » Mon Apr 15, 2019 7:56 pm

Dear ESP-lovers,

I'm currently running one of my ESP32's as replacement for a broken rain sensor.
It measures temperature, humidity and pressure every 30minutes, broadcast it through WiFi and goes to deep sleep inbetween.

The rain sensor is a see saw and is connected to one of the GPIO's so whenever an impulse is generated, the ESP32 stores it in RTC memory.
When it's time to broadcast temperature, ... it also hands over the number of impulses of the rain sensor.

I'm using this coding fragment:
esp_sleep_enable_ext0_wakeup(GPIO_NUM_13,1);
esp_sleep_enable_timer_wakeup(30MINUTES);
esp_deep_sleep_start();

Unfortunately - or logically - the 30MINUTES start anew after every impulse of the rain sensor.

Is there any chance to avoid this?
I'd like to have the 30minutes to be the stable timing.

I've got a picture in mind how I could solve it in software. But then I would need to activate the WiFi whenever there's a GPIO impulse to receive the current (NTP) time and compare it with the previously stored one.
Not my favorite as the device is running on a LiFePO4 and WiFi is a bit energy-hungry.

Thanks a lot for any help or thoughts
obod0002

ESP_igrr
Posts: 1503
Joined: Tue Dec 01, 2015 8:37 am

Re: ESP32 - combining timer AND GPIO wake up

Postby ESP_igrr » Tue Apr 16, 2019 12:05 am

If I understand your problem correctly, you wish to wake up only after certain number of pulses from the sensor, and not on each pulse?
If so, please check the "system/ulp" example in IDF. It demostrates how to do pulse counting using ULP coprocessor, and wake up after given number of pulses.

obod0002
Posts: 19
Joined: Sat Apr 13, 2019 2:34 pm

Re: ESP32 - combining timer AND GPIO wake up

Postby obod0002 » Fri Apr 19, 2019 3:13 pm

thanks a lot for your help. I checked the source code - unfortunately it's a 'little' to sophisticated for my knowledge at the moment. But I'll work on that ... I might come back with some detailled questions when I've understood the basics.

axelmagnus
Posts: 2
Joined: Sat May 25, 2019 9:26 am

Re: ESP32 - combining timer AND GPIO wake up

Postby axelmagnus » Sat May 25, 2019 10:35 am

ESP_igrr wrote:
Tue Apr 16, 2019 12:05 am
If I understand your problem correctly, you wish to wake up only after certain number of pulses from the sensor, and not on each pulse?
If so, please check the "system/ulp" example in IDF. It demostrates how to do pulse counting using ULP coprocessor, and wake up after given number of pulses.
No, I think he wants to do what I also want to do: count rain drops (with ext wake up during deep sleep) and at a certain time interval, say 30 minutes, send that value (and others) to the internet.

Take the case of only one rain drop (say at 13 minutes into the 30 minutes interval):
so, in the code below, the "30MINUTES" must be reduced with 13 minutes.

[Codebox]
esp_sleep_enable_ext0_wakeup(GPIO_NUM_13,1);
esp_sleep_enable_timer_wakeup(30MINUTES-13minutes);
esp_deep_sleep_start();
[/Codebox]

that is, we always want to send our data every 30 minutes, independent of numbers of drops in between, if any. this must be a very common request and design feature. I had a similar desire when a user wakes up the esp32 just to display values on an OLED e.g. without disrupting the send interval.

I think (but cannot really understand the code) that this is what you tried to address in this topic:

viewtopic.php?f=13&t=3344

So, basically, we want to know how long into the 30 minute interval we are, when woken up externally, so we can go to sleep for the appropriate (subtracted) time again. There must be a timer keeping track of the timer-wake up (RTC_CNTL_TIME0_REG??).

It would be nice if we could easily :) access this timer (for any type of wake up).

obod0002
Posts: 19
Joined: Sat Apr 13, 2019 2:34 pm

Re: ESP32 - combining timer AND GPIO wake up

Postby obod0002 » Wed May 29, 2019 9:01 am

thanks for your posts. I finally ended up in doing it like this:

I'm storing the last timer wakeup - ESP32 is collecting NTP time at that moment - in RTC memory.
If rain drops made the ESP to wake up, I'm comparing current ESP time with the one stored in RTC memory.
If difference is bigger than 15minutes I'll connect to WiFi and upload everything stored in ESP's RTC memory.
Timer is set to 20minutes.

I know ESP's clock isn't running pretty accurate, but with this simple coding I'm uploading data roughly every 15 to 35minutes. More than sufficient for my tasks.
Why 15 to 35minutes?
If difference between ESP's local current time and NTP time stored in RTC memory is smaller than 15minutes, no upload will be initiated.
If now a new rain signal is received, an upload is initiated.
But if no rain signal is received, the standard timer of 20minutes becomes effective and 15+20=35minutes.

Biggest concern was to reduce current and hence to not use WiFi too often as everything's powered by a simple LiFePO4.
In case connection to WiFi takes a bit longer and/or collecting NTP time isn't successfully done at once, battery life time is reduced unnecessarily.

axelmagnus
Posts: 2
Joined: Sat May 25, 2019 9:26 am

Re: ESP32 - combining timer AND GPIO wake up

Postby axelmagnus » Sun Jun 02, 2019 9:49 am

What is "current ESP time"? or "ESP clock"? What do you mean, am i missing something?

regards, A

obod0002
Posts: 19
Joined: Sat Apr 13, 2019 2:34 pm

Re: ESP32 - combining timer AND GPIO wake up

Postby obod0002 » Mon Jun 17, 2019 4:47 pm

'current ESP time':
the time the ESP's internal clock believes to be the correct one while all the rest of the world knows the internal clock is loosing or gaining several seconds a day if you don't synchronize it using an NTP server.
I do set the ESP's internal clock every now and then using one of the NPT servers, in fact: I'm using the one of my router.
So from time to time the ESP knows the correct time. If I put it in deep sleep e.g. for 60minutes it wakes up after, no, not 60minutes, but half a minute earlier, or 15seconds later, or ... doesn't matter for my sensors.

'ESP clock': the same e.g. named 'Clock generator' in the ESP32's schematics (upper right corner).

https://www.electronicproducts.com/Digi ... alike.aspx

Who is online

Users browsing this forum: No registered users and 18 guests