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
ESP32 - combining timer AND GPIO wake up
Re: ESP32 - combining timer AND GPIO wake up
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.
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.
Re: ESP32 - combining timer AND GPIO wake up
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.
-
- Posts: 2
- Joined: Sat May 25, 2019 9:26 am
Re: ESP32 - combining timer AND GPIO wake up
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.ESP_igrr wrote: ↑Tue Apr 16, 2019 12:05 amIf 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.
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).
Re: ESP32 - combining timer AND GPIO wake up
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.
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.
-
- Posts: 2
- Joined: Sat May 25, 2019 9:26 am
Re: ESP32 - combining timer AND GPIO wake up
What is "current ESP time"? or "ESP clock"? What do you mean, am i missing something?
regards, A
regards, A
Re: ESP32 - combining timer AND GPIO wake up
'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
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
-
- Posts: 1
- Joined: Tue Apr 28, 2020 11:17 am
Re: ESP32 - combining timer AND GPIO wake up
Hello, obod0002, its possible to share the code?
cumps
cumps
Who is online
Users browsing this forum: Baidu [Spider] and 265 guests