Ok, so the title may sound confusing, but here's what I'm looking to do.
I want to write a library, that will use functions of other libraries. But I want to make sure some of the libraries can be used n an end-user's main code as well.
As an example, one of the things I want to do is create my own wifi manager library. I know there are a bunch out there, but not one of them has all the things I want and the look that I want. So I thought I'd try my hand at making one myself.
In making a wifi library, I would like to use ESPAsyncWebServer to server the configuration pages. However, it is likely that an end-user (myself or otherwise) may want to use ESPAsyncWebServer to server their own pages as well.
Obviously, if they were just simple html pages, you can just put files in the spiffs, ffat or whatever file system you are using and if the wifi manager has the servStatic function setting the root, then any files you upload to the partition in the right place will be served.
What I want to do it to be able to have some lines in the WiFi Library, let's say I want to server some sort of config page from PROGMEM with gzipped content.
server.on("/config", HTTP_GET, [](AsyncWebServerRequest *request) {
AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", configindex_htm_gz, configindex_htm_gz_len);
response->addHeader("Content-Encoding", "gzip");
request->send(response);
}).setAuthentication(Config.AdminUser, Config.AdminPass);
But then I want the end-user to be able to add more "server.on" commands in their own code. I swear I remember a library that did just this in the past, though I can't remember what it was to look it up. It was more of an OTA Update thing, but had WiFi config in it too.
How would one go about doing something like this, whether for this library or any other one? I appreciate any help with this as I can't seem to find the right terms to search for and have never done this before. I tried including the ESPAsyncWebServer.h in my library code, which defines "AsyncWebServer server(80);" in the cpp file as well as setting the include in my main program, but two things happen.
- I try using server.on in my main code, outside of the library files, obviously this doesn't work. I get the message, "error: 'server' was not declared in this scope; did you mean 'Server'?"
- If I add the "AsyncWebServer server" declaration in the library as well as in the main program, of course, I get a message about multiple declaraions.
Is there a way around this, to have either the main program use the declaration from the library or the library use the declaration in the main program?