Schedule tasks

Jbeard
Posts: 2
Joined: Sun Sep 13, 2020 12:17 am

Schedule tasks

Postby Jbeard » Sun Sep 13, 2020 12:35 am

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.

lbernstone
Posts: 828
Joined: Mon Jul 22, 2019 3:20 pm

Re: Schedule tasks

Postby lbernstone » Sun Sep 13, 2020 1:57 pm

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.

Code: Select all

  int offset = 0; // midnight UTC
  if ((time(NULL) % 86400) == offset) {
    send_email;
  }
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.

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 82 guests