Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
70ea3d30bThis file is pinned to the selected release. Download the original to open it in your design tool.
#ifndef WEBSERVER_H
#define WEBSERVER_H
#include "../Logger/logger.h"
#include "../statuscallback.h"
#include <ArduinoJson.h>
#include <ESP8266HTTPUpdateServer.h>
#include <ESP8266WebServer.h>
#include <LittleFS.h>
class Webserver {
public:
Webserver(Logger &log, FS fs, int port = 80) : _logger(log), _fs(fs), _server(port), _statuscallback(emptyStatus) {
_fs.begin();
_httpUpdateServer.setup(&_server);
_server.onNotFound([this]() { _server.send(404, "text/plain", "File not found"); });
};
void useDefaultEndpoints();
void begin();
void handleClient();
void sendJson(const JsonDocument &json, int httpCode = 200);
void sendText(const String &content, int httpCode = 200);
const String &arg(const String &name) const;
void serveStatic(const char *, const char *path, const char *cacheheader = "max-age=300");
void on(const String &uri, ESP8266WebServer::THandlerFunction fn) { _server.on(uri, fn); }
void on(const String &uri, HTTPMethod method, ESP8266WebServer::THandlerFunction fn) {
_server.on(uri, method, fn);
}
void on(const String &uri, HTTPMethod method, ESP8266WebServer::THandlerFunction fn,
ESP8266WebServer::THandlerFunction ufn) {
_server.on(uri, method, fn, ufn);
}
void onStatus(StatusCallback callback) { _statuscallback = callback; }
private:
Logger &_logger; // Reference to the logger
FS _fs;
ESP8266WebServer _server;
ESP8266HTTPUpdateServer _httpUpdateServer;
StatusCallback _statuscallback;
};
#endif // WEBSERVER_H