Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Can't enable SSL for ESP32: error: 'AcSSlFileHandler' has not been declared #1183

Description

@strocode

Hi,

I'm trying to enable SSL for ESP32 - perhaps this isn't supported? I've scraped together a few hints from various posts.

I'm using platformio and versions described below.

The error I get on compile is:

In file included from src/main.cpp:17:
.pio/libdeps/nodemcu-32s/ESP Async WebServer/src/ESPAsyncWebServer.h:412:27: error: 'AcSSlFileHandler' has not been declared
     void onSslFileRequest(AcSSlFileHandler cb, void* arg);
                           ^~~~~~~~~~~~~~~~
Compiling .pio/build/nodemcu-32s/libea0/WiFi/WiFiUdp.cpp.o
src/main.cpp: In function 'void initSecureWebserver()':
src/main.cpp:85:10: error: invalid user-defined conversion from 'initSecureWebserver()::<lambda(void*, const char*, uint8_t**)>' to 'int' [-fpermissive]
   }, NULL);
          ^
src/main.cpp:69:82: note: candidate is: 'initSecureWebserver()::<lambda(void*, const char*, uint8_t**)>::operator int (*)(void*, const char*, uint8_t**)() const' <near match>
   server.onSslFileRequest([](void * arg, const char *filename, uint8_t **buf) -> int {
                                                                                  ^~~
src/main.cpp:69:82: note:   no known conversion from 'int (*)(void*, const char*, uint8_t**)' {aka 'int (*)(void*, const char*, unsigned char**)'} to 'int'
In file included from src/main.cpp:17:
.pio/libdeps/nodemcu-32s/ESP Async WebServer/src/ESPAsyncWebServer.h:412:10: note:   initializing argument 1 of 'void AsyncWebServer::onSslFileRequest(int, void*)'
     void onSslFileRequest(AcSSlFileHandler cb, void* arg);

Code is:

// Tried to Add SSL but it didn't work
// .pio/libdeps/nodemcu-32s/ESP Async WebServer/src/ESPAsyncWebServer.h:412:27: error: 'AcSSlFileHandler' has not been declared
#define ASYNC_TCP_SSL_ENABLED 1 

#include <Arduino.h>

#define WIFI_SSID "WIFI_SSID_1"
#define WIFI_PASSWORD "PASSWORD_FOR_WIFI_SSID_1"
#include <WiFiMulti.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <ESPmDNS.h>
#include "SPIFFS.h"

WiFiMulti wifiMulti;
AsyncWebServer server(443);


void initWifi()
{
    // Setup wifi
  WiFi.mode(WIFI_STA);
  wifiMulti.addAP(WIFI_SSID, WIFI_PASSWORD);
  while (wifiMulti.run() != WL_CONNECTED) {
    Serial.print(".");
    delay(100);
  }
  Serial.print(' ');
  Serial.println(WiFi.localIP());
}

// Tried to add SSL but it didn't work
// Need to add this; https://github.com/me-no-dev/ESPAsyncWebServer/issues/75
void initSecureWebserver()
{
    // Web Server Root URL
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send(SPIFFS, "/index.html", "text/html");
  });

  server.serveStatic("/", SPIFFS, "/");

  server.onSslFileRequest([](void * arg, const char *filename, uint8_t **buf) -> int {
    Serial.printf("SSL File: %s\n", filename);
    File file = SPIFFS.open(filename, "r");
    if(file){
      size_t size = file.size();
      uint8_t * nbuf = (uint8_t*)malloc(size);
      if(nbuf){
        size = file.read(nbuf, size);
        file.close();
        *buf = nbuf;
        return size;
      }
      file.close();
    }
    *buf = 0;
    return 0;
  }, NULL);

  // Start server
  server.beginSecure("/Cert.pem", "/Key.pem", NULL);
}

// Initialize SPIFFS
void initSPIFFS() {
  if (!SPIFFS.begin()) {
    Serial.println("An error has occurred while mounting SPIFFS");
  }
  Serial.println("SPIFFS mounted successfully");
}

void setup() {
  Serial.begin(115200);
  initWifi();
  initSPIFFS();
  initSecureWebserver();
}


void loop() {
  Serial.println("Wait 10s");
  delay(10000);
}

platformio.ini is:

[env:nodemcu-32s]
platform = espressif32
board = nodemcu-32s
framework = arduino
monitor_speed = 115200
lib_deps = 
	https://github.com/me-no-dev/ESPAsyncWebServer.git # need latest version as the ESP Async WebServer has bugs

Dependencies are:

> Executing task in folder AsyncServerSSLTEst: platformio pkg list --environment nodemcu-32s <

Resolving nodemcu-32s dependencies...
Platform espressif32 @ 5.0.0 (required: espressif32)
├── framework-arduinoespressif32 @ 3.20003.220626 (required: platformio/framework-arduinoespressif32 @ ~3.20003.0)
├── tool-esptoolpy @ 1.30300.0 (required: platformio/tool-esptoolpy @ ~1.30300.0)
├── tool-mkfatfs @ 2.0.1 (required: platformio/tool-mkfatfs @ ~2.0.0)
├── tool-mklittlefs @ 1.203.210628 (required: platformio/tool-mklittlefs @ ~1.203.0)
├── tool-mkspiffs @ 2.230.0 (required: platformio/tool-mkspiffs @ ~2.230.0)
└── toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch3 (required: espressif/toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch3)

Libraries
└── ESP Async WebServer @ 1.2.3+sha.f71e3d4 (required: git+https://github.com/me-no-dev/ESPAsyncWebServer.git)
│   └── AsyncTCP @ 1.1.1 (required: me-no-dev/AsyncTCP @ ^1.1.1)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions