ESP2866WebServer and ESP.DeepSleep()

I want to have WebServer for maybe 10 seconds or until I have clients sending requests and than I want DeepSleep for maybe 20 seconds. I have tried this but it's not working. I am sending only loop function.

void loop(void){ server.handleClient(); ESP.deepSleep(20e6); // 20e6 is 20 microseconds }

You want code to poll for the connection for 10 seconds, end then sleep for 20 seconds?

Cheers, Kari

Yes. And if there is somebody connected to server than I don't want DeepSleep. DeepSleep only if there is no activity on WebServer. Thank you.

Ok. How is your code doing so far? What is your problem with code? How can wen help you to write it?

Cheers, Kari

Hello, my code is not doing so well. Today I am coding without DeepSleep, just connecting to wifi and starting WebServer, logging to web page. All that was working today, but than I changed Wifi because my ESP2866 will change places in reality in big supermarket and I couldnt run WebServer, I got message that it is connected to wifi but server didn't start. Than I returned to first wifi and server started, I succesfull log in web page. And one more thing that confuses me is that Serial.println("HTTP server started") sometimes not sometimes yes, and still I am able to log in. I will send you code that troubels me. Thanks in advance.

int connect () { Serial.printf("wake = %d\n", WiFi.forceSleepWake()); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password);

unsigned long wifiConnectStart = millis();

while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); if (millis() - wifiConnectStart > 7000) { Serial.println("Failed to connect to WiFi"); return 0; } } Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); return 1; }

void setup() { Serial.begin(115200); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); // I never see this in output. I don't know why

if (WiFi.SSID() != "") { Serial.println(F("WiFi credentials set in flash, wiping them")); WiFi.disconnect(); }

if (WiFi.getAutoConnect()) { Serial.println(F("Disabling auto-connect")); WiFi.setAutoConnect(false); }

WiFi.persistent(false);

server.on("/", handleRoot); //... now here is some sever callback functions and collections server.begin(); Serial.println("HTTP server started"); int i = connect(); }

void loop() { server.handleClient(); }

Thesse are first lines of Serial: ......... WiFi connected IP address: 192.168.0.129 Enter handleRoot Enter is_authentified

I think my ESP remmebers first succesful connection to WiFi and that makes me problems later with WebServer. I repeat, I recive Serial message that I am succesfully connected on other Wifi, when I try that, but server is not working. An I have disconnect function but I don't know how to use it.

void disconnect () { WiFi.disconnect(true); Serial.printf("sleep 1us = %d\n", WiFi.forceSleepBegin(1)); }

There's no way to understand your code, it is missing too much information.

And use code tags next time, thank you.

Cheers, Kari