The best idea I can come up with is like:
#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.