Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to send a Webpage from ESP32 ? #99

Closed
Stargazer32584 opened this issue Nov 16, 2020 · 7 comments
Closed

Is it possible to send a Webpage from ESP32 ? #99

Stargazer32584 opened this issue Nov 16, 2020 · 7 comments
Labels

Comments

@Stargazer32584
Copy link

Hi,

the ConfigManager is the perfect libary for me and the projects in the future.

But one question is in my mind.

From a release before i using the ConfigManager, the ESP32 have send a simple html-site with some values, if i sebd a request to: http://ESP32IP/site .

But with the ConfigManager, there is no result when he loads the page.

Is it possible to send this page ?

Best regards

André

@nrwiersma
Copy link
Owner

@Stargazer32584
Copy link
Author

Hi,

like this way ?

server->on("/site", HTTPMethod::HTTP_GET, [server](){ server->on("/site", handle_OnConnect);

But there is no result...

Thanks a lot !

@nrwiersma
Copy link
Owner

No, like:

const char *siteHTML = (char *)"/site.html";

server->on("/site", HTTPMethod::HTTP_GET, [server](){
    configManager.streamFile(siteHTML, mimeHTML);
});

You will need to upload site.html into your SPIFFS. You can look to https://github.com/nrwiersma/ConfigManager#additional-files-saved for information.

@Stargazer32584
Copy link
Author

Ah...
But, there is aktually no html-file as site.html. The ESP32 sends it as a String like:

`void handle_OnConnect() {

server.send(200, "text/html", SendHTML());

}

String SendHTML() {
String ptr = " \n";
ptr += "<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">\n";
ptr += "<title>BLEScanner f&uumlr Shelly</title>\n";
ptr += "<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}\n";
ptr += "body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;}\n";
ptr += "p {font-size: 24px;color: #444444;margin-bottom: 10px;}\n";
ptr += "</style>\n";
ptr += "\n";
ptr += "\n";
ptr += "<div id="webpage">\n";
ptr += "

BLEScanner f&uumlr Shelly

\n";
ptr += "

Gescanntes Device 1: ";
ptr += "\n";
ptr += "\n";
ptr += "\n";
return ptr;
}`

So, he generate the answer from his own code. Is this possible in combination with your libary ?

Thanks..

@nrwiersma
Copy link
Owner

... config manager setup
configManager.setAPICallback(APICallback);
....

void APCallback(WebServer *server) {
    server->on("/site", HTTPMethod::HTTP_GET, [server](){
        server.send(200, "text/html", SendHTML());
    });
}

@Stargazer32584
Copy link
Author

Tried it.
The following compilation error appears:

"request for member 'send' in 'server', which is of pointer type 'WebServer* const' (maybe you meant to use '->' ?)

Then, i switched to:

server->on("/site", HTTPMethod::HTTP_GET, [server](){ server->send(200, "text/html", SendHTML()); });

..and what should i say....?

Thanks again, man. It works...!!

Thanks a lot and best regards...

André

@nrwiersma
Copy link
Owner

No problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants