ESP8266_Treppenlicht/lib/httpserver/httpserver.h

42 lines
860 B
C
Raw Normal View History

2021-06-27 00:01:25 +00:00
// Wrapper for ESP8266WebServer with Filesystem as HTTP source
#pragma once
2021-06-22 18:25:27 +00:00
#include <ESP8266WebServer.h>
2021-06-26 19:11:19 +00:00
#include <stdarg.h>
#include "filesys.h"
// debug log <ESP8266WebServer.h>
// #define DEBUGV(f,...) do { Serial.printf(PSTR(f), ##__VA_ARGS__); } while (0)
2021-06-26 19:11:19 +00:00
#define LOG_STR "[HTTPServer]"
2021-06-22 18:25:27 +00:00
2021-06-23 14:12:19 +00:00
class HTTPServer : public ESP8266WebServer {
2021-06-22 18:25:27 +00:00
private:
2021-06-26 19:11:19 +00:00
const char* rootDir = "/";
2021-06-23 13:22:38 +00:00
void listRoot() {
ls(rootDir);
}
2021-06-26 19:11:19 +00:00
void logf(const char *format, ...) {
va_list args;
va_start(args, format);
Serial.print(LOG_STR);
Serial.printf(format, args);
va_end(args);
}
2021-06-22 18:25:27 +00:00
public:
2021-06-23 14:12:19 +00:00
HTTPServer(const int _port, const char* _rootDir) :
ESP8266WebServer(_port), rootDir(_rootDir)
2021-06-23 13:22:38 +00:00
{ }
~HTTPServer()
{
2021-06-23 14:12:19 +00:00
Serial.printf("[HTTPServer] shut down ...\n\r");
2021-06-22 18:25:27 +00:00
}
bool start();
2021-06-22 18:25:27 +00:00
};