6
6
7
7
WebServer::WebServer (SettingsStorage* _settings) {
8
8
settings = _settings;
9
- httpd = ESP8266WebServer (HTTPD_PORT);
9
+ httpd = new ESP8266WebServer (HTTPD_PORT);
10
10
}
11
11
12
12
/* *
@@ -20,16 +20,16 @@ void WebServer::begin() {
20
20
// std::bind wraps a non-static method call so we can pass it as
21
21
// a regular function pointer
22
22
// 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 ();
29
29
}
30
30
31
31
void WebServer::handleNotFound () {
32
- httpd. send (404 , " text/plain" , " Not found" );
32
+ httpd-> send (404 , " text/plain" , " Not found" );
33
33
}
34
34
35
35
void WebServer::handleSet () {
@@ -40,10 +40,10 @@ void WebServer::handleSet() {
40
40
41
41
// Iterate over all keys
42
42
// TODO: handle remaining keys
43
- for (int i = 0 ; i < httpd. args (); i++) {
43
+ for (int i = 0 ; i < httpd-> args (); i++) {
44
44
45
- key = httpd. argName (i);
46
- value = httpd. arg (i);
45
+ key = httpd-> argName (i);
46
+ value = httpd-> arg (i);
47
47
48
48
bool valid = true ;
49
49
@@ -76,9 +76,9 @@ void WebServer::handleSet() {
76
76
}
77
77
78
78
if (fail) {
79
- httpd. send (500 , " text/plain" , msg);
79
+ httpd-> send (500 , " text/plain" , msg);
80
80
} else {
81
- httpd. send (200 , " text/plain" , msg);
81
+ httpd-> send (200 , " text/plain" , msg);
82
82
}
83
83
}
84
84
@@ -107,22 +107,22 @@ void WebServer::handleGet() {
107
107
String buf;
108
108
object.printTo (buf);
109
109
110
- httpd. send (200 , " application/json" , buf);
110
+ httpd-> send (200 , " application/json" , buf);
111
111
112
112
}
113
113
114
114
void WebServer::update () {
115
- httpd. handleClient ();
115
+ httpd-> handleClient ();
116
116
}
117
117
118
118
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
120
120
// From my reading of the source code, this does not happen automatically
121
121
trigger ();
122
- httpd. send (200 , " text/plain" , " OK" );
122
+ httpd-> send (200 , " text/plain" , " OK" );
123
123
}
124
124
125
125
// Execute a callback if the given uri is requested via POST
126
126
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));
128
128
}
0 commit comments