10-21-2022 03:55 PM - edited 10-21-2022 04:08 PM
Hello,
i might be wrong and if so i apologize but here's my understanding about the deep sleep example reported here
The assumption here is that:
The example error is in the last point where the code subtracts esp_timer_get_time() by doing so you are taking into account all the "do other stuff" that are happening in between
My solution is than
void loop() {
int64_t since_start = esp_timer_get_time(); // this is the amount of time the "setup" function takes to run
if (sensor.run(GetTimestamp())) {
//...
}
// do other stuff
uint64_t time_us = ((sensor.nextCall - GetTimestamp()) * 1000) - since_start;
esp_sleep_enable_timer_wakeup(time_us);
esp_deep_sleep_start();
}
This is also supported by the fact that if ones add
int64_t calltime = GetTimestamp();
Let me know if i got it wrong, especially in the assumption part
Solved! Go to Solution.
11-11-2022 02:41 AM
Hi itsmaxdd,
Your assumption is right, the real misunderstanding is about the function esp_timer_get_time().
This function is to get time in microseconds since boot, returns number of microseconds since underlying timer has been started.
Your misunderstood it as getting time stamp.