using wifimanager , setInterval and deepsleep is impossible?

Hello :slight_smile:
I want to sense temp and send it to my server and want my device to sleep for some seconds(or minutes) and then, back to sense temp and get back to sleep ... repeat those process forever.

void setup(){
wifiManager.autoConnect("AutoConnectAP");
}
void loop()
{
  timer.run();
 if (!client.connected()) {
    Serial.println("client connected");
    
        timer.setInterval(10000,repeat);
    
    client.connect("ESP8266Clienttnnttt", mqtt_user, mqtt_password);
    client.subscribe(mqtt_topic);
   
  }
  if(client.connected()){
    client.loop();
  }
}
void repeat(){
  
 //  Here , I sense temp and do http request well. 
 
  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
  Serial.println("Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP) +
  " Seconds");

  Serial.println("Going to sleep now");
  Serial.flush(); 
  esp_deep_sleep_start();
  Serial.println("This will never be printed");
}

when device goes to deep sleep for TIME_TO_SLEEP seconds, device restart and connect to my ssid automatically, but after sleep and wake up for 2 times,

Serial monitor says

*WM:
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: Using last saved values, should be faster
*WM: Connection result:
*WM: 5
*WM: SET AP STA
*WM:
*WM: Configuring access point...
*WM: AutoConnectAP
*WM: AP IP address:
*WM: 192.168.4.1
*WM: HTTP server started

which is not connected to my ssid anymore.

how can I use wifimanager ,setInterval and deepsleep ???

Post complete code!

I get the impression that program a timer to put the device to sleep repeatedly. I don't get the sense behind that. Maybe complete code will put some light on it, maybe it's necessary that you explain it.

Kotran, where you able to solve the issue where after a WAKEUP from DEEPSLEEP the Autoconnect gets into AP mode. I have the same issue and was not able to solve it.