Page 1 of 1

ESP32 Wake stub get elapsed time

Posted: Wed Aug 19, 2020 5:31 am
by dovov97815
Hardware:
Board: ESP32 Dev Module
Core Installation/update date: 16/jun/2020
IDE name: Arduino IDE
Flash Frequency: 80Mhz
PSRAM enabled: no
Upload Speed: 115200
Computer OS: Windows 10

Description:
when wake stub starts I want to know how much time ESP32 spend in deep sleep, how can I achieve this I tried below code in wake stub but always get 0 in return.

Code: Select all

 static const char RTC_RODATA_ATTR now_str[] = "now=%ld\n";

  // Get current RTC time
  SET_PERI_REG_MASK(RTC_CNTL_TIME_UPDATE_REG, RTC_CNTL_TIME_UPDATE);
  while (GET_PERI_REG_MASK(RTC_CNTL_TIME_UPDATE_REG, RTC_CNTL_TIME_VALID) == 0) {
    ets_delay_us(1);
  }
  SET_PERI_REG_MASK(RTC_CNTL_INT_CLR_REG, RTC_CNTL_TIME_VALID_INT_CLR);
  uint64_t now = READ_PERI_REG(RTC_CNTL_TIME0_REG);
  
  now |= ((uint64_t)READ_PERI_REG(RTC_CNTL_TIME1_REG)) << 32;

  ets_printf(now_str,now); // print always 0 here
  

Re: ESP32 Wake stub get elapsed time

Posted: Sat Oct 01, 2022 7:09 am
by snehapawar#
Use below lines of code in start of your main code:


struct timeval now;
gettimeofday(&now, NULL);
int sleep_time_ms = ((now.tv_sec - sleep_enter_time.tv_sec) * 1000) + ((now.tv_usec - sleep_enter_time.tv_usec) / 1000);
printf("sleep_time_ms %d\r\n", sleep_time_ms);


this will give you time spend in deep sleep by esp.