0

i need to wake up my ESP every 60 min to read some data and post it to server, all process working fine when i use numbers of minute below 60 (converted in microsecond x 1000000) but when i use 60 min above i get the following message:

src/main.cpp:137:49: warning: integer overflow in expression of type 'int' results in '-694967296' [-Woverflow] esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);// set up next wake up after 30 sec

How can i make my ESP wake up every 60 min or above?

simplify code:

// for awake and sleep
#define uS_TO_S_FACTOR 1000000 
#define TIME_TO_SLEEP 60 // minute
void setup(){
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * 60 * uS_TO_S_FACTOR);// error if time to sleep more than 60 min 
}
asked Mar 8, 2023 at 3:31
1
  • 1
    More or less the same question here. On the ESP32 the long and int types have the same range. Commented Mar 8, 2023 at 5:27

1 Answer 1

1

Change that line to:

esp_sleep_enable_timer_wakeup((uint64_t) TIME_TO_SLEEP * 60 * uS_TO_S_FACTOR);

That forces the compiler to do 64-bit arithmetic on the constant rather than defaulting to "int" arithmetic.

answered Mar 8, 2023 at 3:51

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.