Hi Leutz,
Ich habe ein merkwürdiges Problem.
Bei meinem vorangegangen ESP8266 Projekt habe ich meine Webseite mit einem Online Tool von String nach hex umgewandelt.
Ich habe dann einfach eine Header Datei angelegt mit dem Array im Progmem:
const uint8_t WEBPAGE[] PROGMEM = {
0x3c,0x21,0x44,0x4f,0x43,0x54,0x59,0x50,0x45,0x20,0x48,0x54,0x4d,0x4c,0x3e,0x0a,0x3c,0x68,
.....
Das Array ist ziemlich groß, so ca 1000 Zeilen Javascript als hex ![]()
Alles lief beim ESP8266 anstandslos.
Binde ich diese h-Datei in meinen ESP32 Sketch ein , sagt er mir:
"Compilation error: 'handleRoot' was not declared in this scope".
#include <WiFi.h>
#include <esp32/sha.h>
#include <HTTPSServer.hpp>
#include <SSLCert.hpp>
#include <HTTPRequest.hpp>
#include <HTTPResponse.hpp>
#include <DNSServer.h>
#include "./webPage.h"
#define DNS_NAME "test3er"
const char* ssid = "ESP32-AP";
const char* password = "123456789";
const byte DNS_PORT = 53;
IPAddress apIP(192, 168, 4, 1);
DNSServer dnsServer;
// The HTTPS Server comes in a separate namespace. For easier use, include it here.
using namespace httpsserver;
SSLCert* cert;
HTTPSServer* secureServer;
void setup() {
Serial.begin(115200);
// First, we create an empty certificate:
cert = new SSLCert();
/* "CN=myesp32.local,O=FancyCompany,C=DE", "20190101000000", "20300101000000" */
String certStr = "CN=" + String(DNS_NAME) + ".local,O=FancyCompany,C=DE";
String dnsStr = "www." + String(DNS_NAME) + ".local";
int createCertResult = createSelfSignedCert(*cert, KEYSIZE_1024, certStr.c_str(), "20190101000000", "20300101000000");
// Now check if creating that worked
if (createCertResult != 0) {
Serial.printf("Cerating certificate failed. Error Code = 0x%02X, check SSLCert.hpp for details", createCertResult);
while (true) delay(500);
}
Serial.println("Creating the certificate was successful");
secureServer = new HTTPSServer(cert);
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
WiFi.softAP(ssid, password);
dnsServer.setTTL(300);
dnsServer.setErrorReplyCode(DNSReplyCode::ServerFailure);
// start DNS server for a specific domain name
dnsServer.start(DNS_PORT, dnsStr.c_str(), apIP);
// For every resource available on the server, we need to create a ResourceNode
// The ResourceNode links URL and HTTP method to a handler function
ResourceNode* nodeRoot = new ResourceNode("/", "GET", &handleRoot);
ResourceNode* node404 = new ResourceNode("", "GET", &handle404);
// Add the root node to the server
secureServer->registerNode(nodeRoot);
// Add the 404 not found node to the server.
secureServer->setDefaultNode(node404);
Serial.println("Starting server...");
secureServer->start();
if (secureServer->isRunning()) {
Serial.println("Server ready.");
}
}
void loop() {
dnsServer.processNextRequest();
secureServer->loop();
}
void handleRoot(HTTPRequest* req, HTTPResponse* res) {
// Status code is 200 OK by default.
// We want to deliver a simple HTML page, so we send a corresponding content type:
res->setHeader("Content-Type", "text/html");
res->write(WEBPAGE, sizeof(WEBPAGE));
}
void handle404(HTTPRequest* req, HTTPResponse* res) {
// Discard request body, if we received any
// We do this, as this is the default node and may also server POST/PUT requests
req->discardRequestBody();
// Set the response status
res->setStatusCode(404);
res->setStatusText("Not Found");
// Set content type of the response
res->setHeader("Content-Type", "text/html");
// Write a tiny HTTP page
res->println("<!DOCTYPE html>");
res->println("<html>");
res->println("<head><title>Not Found</title></head>");
res->println("<body><h1>404 Not Found</h1><p>The requested resource was not found on this server.</p></body>");
res->println("</html>");
}
Das irgendwelche RAM Speicher voll sind, wird mir nicht angezeigt.
Irgendwer eine Idee?