mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-14 20:46:00 +08:00
Move page Handle definition to class constructor
to avoid to setup handle function for web requests in main setup - define handles function in class creator
This commit is contained in:
parent
c74d8235dd
commit
6365055734
@ -24,8 +24,16 @@
|
||||
#include <WiFiServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
|
||||
//cannot put it in class then cast it as std::function<void(void)> so put outside
|
||||
void handle_data_interface_root()
|
||||
{
|
||||
data_interface.WebServer.send(200, "text/plain", "hello from esp8266 from port 8888 ");
|
||||
}
|
||||
|
||||
DATAINTERFACE_CLASS::DATAINTERFACE_CLASS (int port):WebServer(port)
|
||||
{
|
||||
//init what will handle "/"
|
||||
WebServer.on("/",HTTP_GET, handle_data_interface_root);
|
||||
}
|
||||
|
||||
DATAINTERFACE_CLASS data_interface(8888);
|
||||
|
@ -75,10 +75,6 @@ void setup() {
|
||||
//setup wifi according settings
|
||||
wifi_config.Setup();
|
||||
delay(1000);
|
||||
//define interfaces
|
||||
//TODO move this to class
|
||||
web_interface.WebServer.on("/", [](){web_interface.WebServer.send(200, "text/plain", "this works as well - port 80");});
|
||||
data_interface.WebServer.on("/", [](){data_interface.WebServer.send(200, "text/plain", "this works as well - port 8888");});
|
||||
//start interfaces
|
||||
web_interface.WebServer.begin();
|
||||
data_interface.WebServer.begin();
|
||||
|
@ -24,8 +24,16 @@
|
||||
#include <WiFiServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
|
||||
//cannot put it in class then cast it as std::function<void(void)> so put outside
|
||||
void handle_web_interface_root()
|
||||
{
|
||||
web_interface.WebServer.send(200, "text/plain", "hello from esp8266 from port 80!");
|
||||
}
|
||||
|
||||
WEBINTERFACE_CLASS::WEBINTERFACE_CLASS (int port):WebServer(port)
|
||||
{
|
||||
//init what will handle "/"
|
||||
WebServer.on("/",HTTP_GET, handle_web_interface_root);
|
||||
}
|
||||
|
||||
WEBINTERFACE_CLASS web_interface(80);
|
||||
|
Loading…
x
Reference in New Issue
Block a user