Chat freely about anything...

User avatar
By Sirquil
#84177 Having a hard time understanding the documentation; especially how use this code::

Code: Select allAsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", MAIN_page);
response->addHeader("Server","ESP Async Web Server");

Do I want to use this code? Does it go inside of "index.h"?

Do I need to change from client.print to response->print syntax?

I did as you suggested and only used MAIN_page and dropped sizeof(MAIN_page). I think this is what you suggested. Also chared back to const char from uint8_t. Compiles; however no web page. Just says loading...

I will go back and read the documentation, again later today.

Thanks for your help.

User avatar
By Pablo2048
#84178 You don't wat to send additional headers so no - don't change anythig. Just start to try with simple example:
Code: Select allconst char index_html[] PROGMEM = "Hello from ESP"; // later on here come your huge webpage
     serverAsync.on("/Weather", HTTP_GET, [](AsyncWebServerRequest * request) {
     request->send_P(200, PSTR("text/html"), index_html);

After calling http://<ip>/Weather from your browser you should see "Hello from ESP" on the screen.
User avatar
By Sirquil
#84193 Simple test worked. Followed up with sending "MAIN_html; which is from imported "index.h." Expected result:

Webpage from created web server code!.JPG
Webpage from created web server code!.

Result of "MAIN_html":

Result of MAIN_html.JPG
Result of MAIN_html from PROGMEN

Code is not all HTML. Is there a way to still use Asyncwebserver?

User avatar
By Pablo2048
#84194 William, from the result image it seems like you mixed things up. Serving page from PROGMEM does not mean that this page can contain Arduino code which has to be executed. I suggest to
1. extract all HTML code from your main page generator to PROGMEM multiline text
2. use template interpreter from AsyncWebServer to fill-in computed variables (its the last parameter from send_P IIRC)