Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By tommytml
#80171 I'm trying to let my esp8266 webserver sleep periodically but can't find a good method to implement a back ground timer and I want the timer to stop counting while there's someone connecting to the sever.
The best idea I can come up with is like:
Code: Select all #include <ESP8266WiFi.h>     
 #include <ESP8266WebServer.h>

void setup(void){
/*
initialize the wifi and web server
*/
timer.start(1 hour);//initialize and start the timer and let it count to 1 hour for example

}
void loop(void){
 if(server.client().connected()){
   timer.restart(1 hour);  //restart the timer so it won't sleep when other users are connected
  }
  server.handleClient(); // the timer is still counting in background
if(timer.count==1 hour ){
 ESP.deepSleep(sometime); // let the server sleep if no one connects it for 1 hour
}

}

I would be grateful if someone can come up with a good method for my idea or a smarter idea.