Schedule tasks
Schedule tasks
I'm new to the esp32 microcontroller. I'm trying to have the esp32 measure temperatures and if they reach a high or low setpoint it emails me with a alarm. I've been able to find a few sketchs and put them together and make it work. I also want to have a email sent every day at a specific time with the current temperature so I know to esp32 is still working. I can't find any sketchs that I can use or figure out how to do this. Could someone please help me with my project. Thank you.
-
- Posts: 828
- Joined: Mon Jul 22, 2019 3:20 pm
Re: Schedule tasks
There's more than one way to do it.
1) In loop, check to see if your time matches. Note that if your loop runs more than once a second, this code will cause dupes.
2) Set a Ticker.once to run when you first want the process run. In that callback, set the ticker to repeat at 24 hours.
1) In loop, check to see if your time matches. Note that if your loop runs more than once a second, this code will cause dupes.
Code: Select all
int offset = 0; // midnight UTC
if ((time(NULL) % 86400) == offset) {
send_email;
}
Code: Select all
#include <Ticker.h>
Ticker tkEmail;
void email_loop() {
tkEmail.once(86400, email_loop);
send_email;
}
void setup() {
...
int offset = 0; // midnight UTC
tkEmail.once((time(NULL) - offset) % 86400, email_loop);
}
Who is online
Users browsing this forum: No registered users and 80 guests