Skip to content

Commit 2252665

Browse files
author
Michael Haas
committed
Fix build with new ESP8266 version
See esp8266/Arduino#4085
1 parent acb9109 commit 2252665

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

src/WebServer.cpp

+18-18
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
WebServer::WebServer(SettingsStorage* _settings) {
88
settings = _settings;
9-
httpd = ESP8266WebServer(HTTPD_PORT);
9+
httpd = new ESP8266WebServer(HTTPD_PORT);
1010
}
1111

1212
/**
@@ -20,16 +20,16 @@ void WebServer::begin() {
2020
// std::bind wraps a non-static method call so we can pass it as
2121
// a regular function pointer
2222
// See e.g. http://arduino.stackexchange.com/questions/14157/passing-class-member-function-as-argument
23-
httpd.serveStatic("/", SPIFFS, "/wwwroot/index.html");
24-
httpd.serveStatic("/smoothie.js", SPIFFS, "/wwwroot/smoothie.js");
25-
httpd.on("/set", HTTP_POST, std::bind(&WebServer::handleSet, this));
26-
httpd.on("/get", HTTP_GET, std::bind(&WebServer::handleGet, this));
27-
httpd.onNotFound(std::bind(&WebServer::handleNotFound, this));
28-
httpd.begin();
23+
httpd->serveStatic("/", SPIFFS, "/wwwroot/index.html");
24+
httpd->serveStatic("/smoothie.js", SPIFFS, "/wwwroot/smoothie.js");
25+
httpd->on("/set", HTTP_POST, std::bind(&WebServer::handleSet, this));
26+
httpd->on("/get", HTTP_GET, std::bind(&WebServer::handleGet, this));
27+
httpd->onNotFound(std::bind(&WebServer::handleNotFound, this));
28+
httpd->begin();
2929
}
3030

3131
void WebServer::handleNotFound () {
32-
httpd.send(404, "text/plain", "Not found");
32+
httpd->send(404, "text/plain", "Not found");
3333
}
3434

3535
void WebServer::handleSet() {
@@ -40,10 +40,10 @@ void WebServer::handleSet() {
4040

4141
// Iterate over all keys
4242
// TODO: handle remaining keys
43-
for (int i = 0; i < httpd.args(); i++) {
43+
for (int i = 0; i < httpd->args(); i++) {
4444

45-
key = httpd.argName(i);
46-
value = httpd.arg(i);
45+
key = httpd->argName(i);
46+
value = httpd->arg(i);
4747

4848
bool valid = true;
4949

@@ -76,9 +76,9 @@ void WebServer::handleSet() {
7676
}
7777

7878
if (fail) {
79-
httpd.send(500, "text/plain", msg);
79+
httpd->send(500, "text/plain", msg);
8080
} else {
81-
httpd.send(200, "text/plain", msg);
81+
httpd->send(200, "text/plain", msg);
8282
}
8383
}
8484

@@ -107,22 +107,22 @@ void WebServer::handleGet() {
107107
String buf;
108108
object.printTo(buf);
109109

110-
httpd.send(200, "application/json", buf);
110+
httpd->send(200, "application/json", buf);
111111

112112
}
113113

114114
void WebServer::update() {
115-
httpd.handleClient();
115+
httpd->handleClient();
116116
}
117117

118118
void WebServer::handleTrigger(ESP8266WebServer::THandlerFunction trigger) {
119-
// Small wrapper around a trigger which calls httpd.send() to end the connection
119+
// Small wrapper around a trigger which calls httpd->send() to end the connection
120120
// From my reading of the source code, this does not happen automatically
121121
trigger();
122-
httpd.send(200, "text/plain", "OK");
122+
httpd->send(200, "text/plain", "OK");
123123
}
124124

125125
// Execute a callback if the given uri is requested via POST
126126
void WebServer::addTrigger(const char* uri, ESP8266WebServer::THandlerFunction trigger) {
127-
httpd.on(uri, HTTP_POST, std::bind(&WebServer::handleTrigger, this, trigger));
127+
httpd->on(uri, HTTP_POST, std::bind(&WebServer::handleTrigger, this, trigger));
128128
}

src/WebServer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class WebServer {
2727
const char* KD_KEY = "kd";
2828
const int HTTPD_PORT = 80;
2929
SettingsStorage* settings;
30-
ESP8266WebServer httpd;
30+
ESP8266WebServer* httpd;
3131
void handleRoot();
3232
void handleNotFound();
3333
void handleSet();

0 commit comments

Comments
 (0)