Accessing index.html file on SD card #179
Unanswered
sebastian1967
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I should need to access to my web server files that are stored on a SD card. In particular I would open the index.html page. How can I do this? The code from wich I'm starting is here under. In particlar I don't understand how to change this part here:
ResourceNode* nodeRoot = new ResourceNode("/", "GET", [](HTTPRequest* req, HTTPResponse* res) { res->println("Secure Hello World!!!"); });
Full code here:
`#include <WiFi.h>
#include <HTTPSServer.hpp>
#include <SSLCert.hpp>
#include <HTTPRequest.hpp>
#include <HTTPResponse.hpp>
using namespace httpsserver;
#include "FS.h"
#include "SD.h"
#include "SPI.h"
// Replace with your network credentials
const char* ssid = "ESP32-Access-Point";
const char* password = "123456789";
SSLCert* cert;
HTTPSServer* secureServer;
bool SD_present;
int chipSelect = 5;
void initSDCard() {
if (!SD.begin(chipSelect, SPI, 4000000U, "/sd", 10U, false)) {
Serial.println(F("Card failed or not present, no SD Card data logging possible..."));
SD_present = false;
}
uint8_t cardType = SD.cardType();
if (cardType == CARD_NONE) {
Serial.println("No SD card attached");
return;
}
Serial.print("SD Card Type: ");
if (cardType == CARD_MMC) {
Serial.println("MMC");
} else if (cardType == CARD_SD) {
Serial.println("SDSC");
} else if (cardType == CARD_SDHC) {
Serial.println("SDHC");
} else {
Serial.println("UNKNOWN");
}
uint64_t cardSize = SD.cardSize() / (1024 * 1024);
Serial.printf("SD Card Size: %lluMB\n", cardSize);
}
void setup() {
Serial.begin(115200);
initSDCard();
delay(1000);
// Connect to Wi-Fi network with SSID and password
Serial.println("Creating certificate...");
cert = new SSLCert();
int createCertResult = createSelfSignedCert(
*cert,
KEYSIZE_2048,
"CN=myesp.local,O=acme,C=US");
if (createCertResult != 0) {
Serial.printf("Error generating certificate");
return;
}
Serial.println("Certificate created with success");
secureServer = new HTTPSServer(cert);
Serial.print("Setting AP (Access Point)… ");
// Remove the password parameter, if you want the AP (Access Point) to be open
WiFi.softAP(ssid, password);
IPAddress IP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(IP);
/* server.on("/", HTTP_GET, [](AsyncWebServerRequest* request) {
request->send(SD, "/index.html"); //, "text/html");
});
server.serveStatic("/", SD, "/");
server.begin();*/
ResourceNode* nodeRoot = new ResourceNode("/", "GET", [](HTTPRequest* req, HTTPResponse* res) {
res->println("Secure Hello World!!!");
});
//server.serveStatic("/", SD, "/");
secureServer->registerNode(nodeRoot);
secureServer->start();
if (secureServer->isRunning()) {
Serial.println("Server ready.");
}
}
void loop() {
secureServer->loop();
delay(10);
}`
Beta Was this translation helpful? Give feedback.
All reactions