Callback function processor template AsyncWebServer

hi,
hi i have create a class with che async web server but not setting processor

my h file is

class Webserver { public: explicit Webserver(Config *cfg, Debug *debug, uint8_t port = 80) : cfg(cfg), debug(debug), server(port) {}; void Start(void); private: Config *cfg; Debug *debug; AsyncWebServer server; String WebpageProcessor_(const String &var); };

and my cpp file is

String Webserver::WebpageProcessor_(const String &var) {
if (var == "fw_name") {
return cfg->GetFWName();
}
}
void Webserver::Start(void) {
debug->DEBUG_PRINTLN("[WEBSERVER] Initializze WebServer...");
debug->DEBUG_PRINTLN(cfg->GetFWName());
//Route for restart ESP
server.on("/restart", HTTP_POST, [](AsyncWebServerRequest *request) {
ESP.restart();
});

// Route for web page
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(SD, "/index.html", "text/html", false, WebpageProcessor_);
});

// Route for not found web page
server.onNotFound([](AsyncWebServerRequest *request) {
Serial.printf("[404] Not Found: http://%s%s", request->host().c_str(), request->url().c_str());
request->send(404);
});



server.serveStatic("/", SD, "/");

server.begin();
debug->DEBUG_PRINTLN("[WEBSERVER] WebServer Started...");
}

but this row

request->send(SD, "/index.html", "text/html", false, WebpageProcessor_);

not work :frowning: :frowning:

we can help me please?

What does that mean? Does it not compile? Or when running the sketch on the ESP it does not do what you expected?.

Based on the snippet that you posted, you might not get many useful replies. I suggest that you post your full code or a minimal example that shows the problem.

I'm not an ESP user and have no experience with web stuff in the Arduino environment so can't advise.

i find the solution

    server.on("/", HTTP_GET, [&](AsyncWebServerRequest *request) {
    request->send(SD, "/index.html", "text/html", false, [&](const String &var) -> String {
                      return WebpageProcessor_(var);
                    });
  });

tnks you for all

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.