The problem is that I have to reset the board every 3 minutes because the web server stops working.
I do not kno why... I can use it for 2 or 3 minutes... then it stops.
Any sugestion?
I attach my code:
#include <ESP8266WiFi.h>
#include <TimeLib.h>
const char* ssid = "***********************";
const char* password = "********************";
int ledPin = 14; // GPIO14
int myport = 80;
String actionToDo = "";
WiFiServer server(myport);
void setup() {
Serial.begin(115200);
delay(10);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.print(":");
Serial.print(myport);
Serial.println("/");
}
void loop() {
// listen for incoming clients
WiFiClient client = server.available();
if (!client) {
if (now() >= 180) {
ESP.restart(); //why don't you work?!?
}
return;
}
Serial.println("new client");
// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
if (request.indexOf("/WAKEUP") != -1) {
actionToDo = "WakeUp";
} else if (request.indexOf("/SHUTDOWN") != -1) {
actionToDo = "ShutDown";
}
Serial.println(actionToDo);
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<br />");
client.println(actionToDo);
client.println(now());
client.println("<br />");
client.println("</html>");
// give the web browser time to receive the data
delay(1);
// close the connection:
Serial.println("client disconnected");
if (actionToDo == "WakeUp") {
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
} else if (actionToDo == "ShutDown") {
digitalWrite(ledPin, HIGH);
delay(7000);
digitalWrite(ledPin, LOW);
}