ESPMegaPRO-v3-SDK/ESPMegaPRO-firmware/lib/ESPMegaPRO/ESPMegaWebServer.hpp

49 lines
1.4 KiB
C++
Raw Normal View History

2023-12-29 18:23:33 +00:00
#pragma once
2023-12-31 08:53:39 +00:00
#include <FS.h>
2023-12-29 18:23:33 +00:00
#include <ESPAsyncWebServer.h>
#include <ESPMegaIoT.hpp>
#include <Update.h>
2024-01-01 13:30:17 +00:00
#include <FRAM.h>
2024-01-01 09:38:14 +00:00
#include <html/all.h>
2023-12-29 18:23:33 +00:00
2024-01-01 13:30:17 +00:00
/**
* @brief Provides a web server for ESPMegaPRO
*
* This class use FRAM address 301-400
*/
2023-12-29 18:23:33 +00:00
class ESPMegaWebServer
{
public:
2024-01-01 06:28:15 +00:00
ESPMegaWebServer(uint16_t port, ESPMegaIoT *iot);
2023-12-29 18:23:33 +00:00
~ESPMegaWebServer();
2024-01-01 06:28:15 +00:00
void begin();
2023-12-29 18:23:33 +00:00
void loop();
2024-01-01 13:30:17 +00:00
void resetCredentials();
char* getWebUsername();
char* getWebPassword();
void setWebUsername(const char* username);
void setWebPassword(const char* password);
void bindFRAM(FRAM *fram);
void loadCredentialsFromFRAM();
void saveCredentialsToFRAM();
2023-12-29 18:23:33 +00:00
private:
2024-01-01 13:30:17 +00:00
// FRAM
FRAM *fram;
// Credentials
char webUsername[32];
char webPassword[32];
2023-12-29 18:23:33 +00:00
// Web Server
2024-01-01 06:28:15 +00:00
AsyncWebServer *server;
2023-12-29 18:23:33 +00:00
uint16_t port;
// ESPMegaIoT
ESPMegaIoT *iot;
// Endpoints Handlers
void dashboardHandler(AsyncWebServerRequest *request);
2024-01-01 09:38:14 +00:00
String dashboardProcessor(const String& var);
2023-12-29 18:23:33 +00:00
void configHandler(AsyncWebServerRequest *request);
String configProcessor(const String& var);
2023-12-29 18:23:33 +00:00
void saveConfigHandler(AsyncWebServerRequest *request);
void otaHandler(AsyncWebServerRequest *request);
2023-12-31 08:53:39 +00:00
void restAPIHandler(AsyncWebServerRequest *request);
2023-12-29 18:23:33 +00:00
};