• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Conditional sleep/wake?

Q&A Forum › Conditional sleep/wake?
0 Vote Up Vote Down
Jack Douglas asked 2 years ago

Can an esp32 with RTC be woken up based on a conditional time statement (see Example below), or does it require a timer function?  If a timer function is required, how could I have it wake up at the top of the hour every 60 mn?

Even if I need a timer, I would like to use the conditional statement.  I am still learning cpp, so I need a bit of help correcting the syntax.

Example

int minutes = 30 ;

String time_1 ;  << How to set time and convert for compare?

void loop(){
  getTIme();
    if time_1 < time_current < time_1 + minutes  ;       << ?
      wake    ;                                          << ?
        while time_current < time_1 + minutes ;
          do something ;
    else ;

      sleep;                                             << ?              }

void getTime(){
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);

}

void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year){
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
//  Wire.write(0xE); // set DS3231 register pointer to 00h
  Wire.write(0);
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
   timeDate = *dayOfMonth;
   timeDay = *dayOfWeek;
   timeMonth = *month;
   timeYear = *year;
   timeHour = *hour;
   timeMinutes = *minute;
   timeSeconds = *second;
}
Question Tags: ESP32 clock wake sleep
1 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Hi.
While the ESP32 is asleep, you can’t check the time.
You can only check the time when it is awake.
So, you can’t have something like this:
    if time_1 < time_current < time_1 + minutes  ;       << ?
      wake    ;                                          << ?
 
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.