Hi,
I have created a simple lib to handle server calls of ESPAsyncWebServer with template handling function.
If I use that in my main program it is working but I want to sent the callback funtion of my main program to the lib.
I get the following error: 'callback' is not captured.
This is the code of my main program and the lib:
************************************** WebServerTemplate.ino **************************************
#include LittleFS.h>
#include <RokTools.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
AsyncWebServer server(80);
String processor(const String& var){
Serial.println("process variable " + var);
if(var == "TITLE"){
return "ESP - Template";
}
return String();
}
void setup() {
Serial.begin(115200);
if (LittleFS.begin()) {
Serial.println("Filesystem mounted");
}
else {
Serial.println("ERROR!!! Filesystem not mounted...");
}
addDefaultServerRoutes(&server, processor);
server.begin();
}
void loop() {}
************************************** RokTools.h **************************************
#ifndef __ROKTOOLS__
#define __ROKTOOLS__
#include <ESPAsyncWebServer.h> //Local WebServer used to serve the configuration portal
#include "Arduino.h"
extern void addDefaultServerRoutes(AwsTemplateProcessor callback);
#endif
************************************** RokTools.cpp **************************************
#include "RokTools.h"
#include <LittleFS.h> //this needs to be first, or it all crashes and burns...
#include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson
#include "ESPAsyncWebServer.h"
#include "Arduino.h"
void addDefaultServerRoutes(AsyncWebServer *server, AwsTemplateProcessor callback) {
server->on("/", HTTP_GET, [](AsyncWebServerRequest *request){
//COMPILER ERROR => 'callback' is not captured !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
request->send(LittleFS, "/index.html", String(), false, callback);
});
}
It would be great if someone can help me!
Thanks a lot,
Roger