Hope I'm in the correct section - feel free to move my thread if not.
I'm trying to implement the ESP8266WebServer to have it server pages. It works fine as long as everything is in my core script, but not when it's moved into the external library (where, for my project, this functionality belongs). When I do that it serves one and only one page, after that Firefox says "Firefox can’t establish a connection to the server" and that's it, until I reset the thing. In the meantime it does however respond to pings.
As my code is spread out over classes and way too big to post here all (and I don't have git set up yet), hereby the relevant snippets. Setup is not complete (it adds code for OTA and connecting to the WiFi, all of which works great). Function loop is complete, this is all that's in there.
Other notable behaviour of the ESP8266WebServer is that the very first request takes about 5 seconds to be served, while any subsequent requests come instantly. Connecting my PC and the ESP8266 to the same WiFi router (the PC has a wired connection).
.ino script:
void setup() {
master.begin();
}
void loop() {
master.execute();
ArduinoOTA.handle();
}
from master.cpp:
void HydroMonitorMaster::begin() {
Serial.print(F("Size (in bytes) of settings: "));
Serial.println(String(sizeof(settings)));
// Initialise the EEPROM storage.
EEPROM.begin(EEPROM_SIZE);
// Start by trying to read the existing settings from flash storage.
readSettings();
// Set up the http request handlers.
server.on("/", std::bind(&HydroMonitorMaster::handleRoot, this));
server.begin();
yield();
return;
}
void HydroMonitorMaster::execute() {
// Check for incoming connections.
server.handleClient();
}
from master.h:
public:
void execute(void);
private:
void handleRoot();
Now when I add the following to master, it works:
void HydroMonitorMaster::handleRoot() {
server.send(200, "text/html", "Request for ROOT received.");
}
But when I want to offload the html response to a second class it fails. The page is loaded the first time I request it, but not any more after that.
Alternative code for master.cpp:
void HydroMonitorMaster::handleRoot() {
network.htmlResponse(server, "test HTML network class response!");
}
This calls a function in HydromonitorNetwork.cpp:
void HydroMonitorNetwork::htmlResponse(ESP8266WebServer server, String response) {
server.send(200, "text/html", response);
return;
}