Crashing of ESP8266WebServer.h

I’m having problems with my ESP8266’s web serving abilities. Currently if I start it up and try to access the web page it loads a few times and works as it should but then just stops responding. The number of times it works varies from one to zero. If i leave it for a time it will stop responding on its own and eventually it reboots on its own.

Any suggestions of how to debug? My serial output is still working as it displays the NTP but once the server stops responding it no longer shows a tick per second its closer to 10s. The server must be waiting for something??

This is skeleton code extracted from the project

#include <Adafruit_NeoPixel.h>
#include <TimeLib.h> 
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include "WebPage.h"
#include <ESP8266WebServer.h>
#include <NTPClient.h>
#define PIN            12
#define NUMPIXELS      256//new root handler


void setup() {   
  
  Serial.begin(9600);
  delay(250);
  Serial.println("TimeNTP Example");
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, pass);
    
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
    Serial.print(".");
    }
  
  Serial.print("IP number assigned by DHCP is ");
  Serial.println(WiFi.localIP());
  Serial.println("Starting UDP");
  Udp.begin(localPort);
  Serial.print("Local port: ");
  Serial.println(Udp.localPort());
  Serial.println("waiting for sync");
  //for DST
  timeZone = DST(); 
  Serial.print("DST=");
  Serial.println(timeZone);
  timeClient.begin();
    
    while(timeClient.forceUpdate()==false){
      delay(1000);
    }
    setSyncProvider(getNtpTimeClient);
  
  //start display pixels
  pixels.begin();
  pixels.show();
  pixels.setBrightness(bright);
  delay(1000);

  //start web server
  server.on("/", handleRoot);
  server.on("/submit", handleSubmit);
  server.onNotFound(handleNotFound);
    
  server.begin();
  Serial.println("Starting Web Server");
  Serial.print("Connect to http://");
  Serial.println(WiFi.localIP());
  rainbowCycle(0);  
  }
  
  void loop() {
    // Display Stuff
    clearscreen();
    AnimateTick();
    refreshTime();
    
    //Web Interface
    server.handleClient();
    ProcessCommand();
    
    //NTP
    timeClient.update();
    //SHow time only if seconds changed
    if (now() != prevDisplay) { //update the display only if time has changed
      prevDisplay = now();
      SerialTime();  
    }
    
void handleRoot()
{
  
  if (server.hasArg("line")) {
    handleSubmit();
  }
  else {
    server.send(200, "text/html", INDEX_HTML);
   Serial.println("SERVER HANDLER USED");
  }
  
}

void handleNotFound()
{
  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET)?"GET":"POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i=0; i<server.args(); i++){
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }
  server.send(404, "text/plain", message);
}

void handleSubmit()
{

Serial.println(server.arg("line"));
  if (!server.hasArg("line")) return returnFail("BAD ARGS");
    command = server.arg("line");
    server.send(200, "text/html", "SUCCESS");
  }

  void returnFail(String msg)
{
  server.sendHeader("Connection", "close");
  server.sendHeader("Access-Control-Allow-Origin", "*");
  server.send(500, "text/plain", msg + "\r\n");
}

and webpage.h

#ifndef header_h
#define header_h

const char INDEX_HTML[]=
"<!DOCTYPE html>\r\n"
"<html lang=\"en\">\r\n"
"    <head>\r\n"
"        <meta charset=\"utf-8\">\r\n"
"        <title>Clock Command</title>\r\n"
"    </head>\r\n"
"\r\n"
"    <body \">\r\n"
"<FORM action=\"/\" method=\"post\">"
"        <p><b>Enter a command string</b></p>\r\n"
"        <form id=\"txt_form\" name=\"frmText\">\r\n"
"            <label>Text: <input type=\"text\" name=\"line\" size=\"60\" maxlength=\"60\" /></label>\r\n"
"        </form>\r\n"
"        
\r\n"
"        <input type=\"submit\" value=\"Send\"> <INPUT type=\"reset\">\r\n"
"    </body>\r\n"
"\r\n"
"</html>\r\n";

and webpage.h

Code: [Select]

ifndef header_h

define header_h

The name in the include guard is SUPPOSED to match the name of the file.

const char INDEX_HTML[]=

It may be const, but it still occupies SRAM.

#define NUMPIXELS      256//new root handler

Are you using the ESP with 2 terabytes of memory?

The ESP may have more memory, but you are making no attempts to keep data out of SRAM.

Lol no it's a node mcu so standard sram (I don't actually know how much?!). Actually a lot of other things are stored in eeprom.

Do you think it's just a ram issue? I can easily move the webpage to eeprom. The neopixel library does use up a fair bit but I've tried and struggled to make it smaller in the past for a nano.

I don't actually know how much?

Why don't you? They do not ship with random amounts of memory. Learn how much yours has.

Do you think it's just a ram issue?

It's certainly a possibility.

I can easily move the webpage to eeprom.

I think (or hope) you meant PROGMEM.

Show all your code except for maybe your wifi credentials.
You appear to be missing a section which would include:
ESP8266WebServer server ( );
Etc.