-
Hi all! As is, I have a project where it’s a standalone webpage served from the ESP32 webserver and WiFi. So to connect is simple; turn on the esp32, on the user device WiFi settings look for the esp32 WiFi network, connect to it, add password, once connected you are in the webpage! My question would be, How can I add my webpage that sits on the SPIFF under a folder named data/page1.html And Run when the HOME button is pressed in the AutoConnect Menu? I have read the Custom page implementation but as you can see my webpage is pure html not json. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 10 replies
-
A description of that technique is given in the documentation as Capture the legacy web pages as items into the menu. server.on("/hello", [](){
server.send(200, "text/html", String(F(
"<html>"
"<head><meta name='viewport' content='width=device-width,initial-scale=1.0'></head>"
"<body><h2>Hello, world</h2></body>"
"</html>"
)));
});
portal.append("/hello", "HELLO"); In that example, it is added as a "HELLO" item into the menu, but you can add a legacy page handler to the HOME menu item by using the AutoConnectConfig::homeUri setting. So, what you need may be had in the sketch below: #include <Arduino.h>
#include <WiFi.h>
#include <WebServer.h>
#include <SPIFFS.h>
#include <AutoConnect.h>
// Change HOME URI and HTML file path you wish.
#define HOMEURI "/home"
#define ADDONPAGEFILE "/data/page1.html"
WebServer server;
AutoConnect portal(server);
AutoConnectConfig config;
bool loadAddonPage(const char* path) {
bool rc = false;
Serial.printf("Page %s requested, ", path);
File addonPage = SPIFFS.open(path, "r");
if (addonPage) {
if (!addonPage.isDirectory()) {
server.streamFile(addonPage, "text/html");
Serial.println("successfully loaded");
rc = true;
}
else
Serial.println("it's directory");
addonPage.close();
}
else
Serial.println("open failed, probably does not exist.");
return rc;
}
void setup() {
delay(1000);
Serial.begin(115200);
Serial.println();
server.on(HOMEURI, HTTP_GET, []() {
if (!loadAddonPage(ADDONPAGEFILE))
server.send(404, "text/plain", "File not found");
});
SPIFFS.begin(true);
config.homeUri = HOMEURI; // It's important
portal.config(config); // Register the HOMEPATH to HOME item of the menu
portal.begin();
}
void loop() {
portal.handleClient();
} |
Beta Was this translation helpful? Give feedback.
-
And on the terminal this is what it shows: EDIT by Hieromon |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
The links don’t work and the images don’t rendered. |
Beta Was this translation helpful? Give feedback.
-
How can I reach out to you, privately? I rather contribute to the person or group that developed the portal. |
Beta Was this translation helpful? Give feedback.
A description of that technique is given in the documentation as Capture the legacy web pages as items into the menu.
The following sketch coded in the above section is a WebServer native page handler:
In that example, it is added as a "HELLO" item into the menu, but you can add a legacy page handler to the HOME menu item by using the AutoConnectConfig::homeUri setting.
So, what you need may be had in the sketch below: