EmlaLockSafe
ConfigurationServerBase.h
Go to the documentation of this file.
1
5#pragma once
6
7#include "../UsedInterrupts.h"
8
9#include <ESPAsyncWebServer.h>
10#include <SPIFFS.h>
11
12namespace configuration {
17protected:
21 AsyncWebServer server;
22
23protected:
28 : server(80) {
29 // Add files to webserver which are loaded from the file system
30 addSpiffsFileToServer("/jquery-3.6.0.min.js", "text/javascript");
31 addSpiffsFileToServer("/main.css", "text/css");
32 }
33
34protected:
43 void addSpiffsFileToServer(const char* path, String contentType, const char* filename = nullptr) {
44 if (!filename) {
45 filename = path;
46 }
47 server.on(path, HTTP_GET, [contentType, filename](AsyncWebServerRequest* request) {
48 UsedInterrupts::executeWithoutInterrupts([request, contentType, filename]() {
49 request->send(SPIFFS, filename, contentType);
50 });
51 });
52 }
53};
54} // namespace configuration
static void executeWithoutInterrupts(std::function< void(void)> f)
Execute the passed function without interrupts.
Definition: UsedInterrupts.h:58
Base class for configuring the controller over WiFi.
Definition: ConfigurationServerBase.h:16
void addSpiffsFileToServer(const char *path, String contentType, const char *filename=nullptr)
Adds the file from the SPIFFS with the filename to the webserver under the given path.
Definition: ConfigurationServerBase.h:43
ConfigurationServerBase()
Construct a new Configuration Server object.
Definition: ConfigurationServerBase.h:27
AsyncWebServer server
The used asynchronous webserver.
Definition: ConfigurationServerBase.h:21
Definition: Configuration.h:16