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 13:56:37 +00:00
|
|
|
#include <ArduinoJson.h>
|
2024-01-01 15:53:28 +00:00
|
|
|
#include <AsyncJson.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
|
|
|
|
*
|
2024-01-01 16:40:32 +00:00
|
|
|
* This class provides a web server for ESPMegaPRO. It is used to configure the device and to update the firmware.
|
|
|
|
* This class also allows to save the credentials to access the web server in the FRAM memory.
|
|
|
|
* User can also add custom endpoints to the web server.
|
|
|
|
*
|
2024-01-01 13:30:17 +00:00
|
|
|
* 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();
|
2024-01-01 16:40:32 +00:00
|
|
|
AsyncWebServer* getServer();
|
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);
|
2024-01-01 10:52:59 +00:00
|
|
|
String configProcessor(const String& var);
|
2024-01-01 15:53:28 +00:00
|
|
|
AsyncCallbackJsonWebHandler *saveConfigHandler;
|
|
|
|
void saveConfigJSONHandler(AsyncWebServerRequest *request, JsonVariant &json);
|
2024-01-01 15:13:54 +00:00
|
|
|
void otaRequestHandler(AsyncWebServerRequest *request);
|
|
|
|
void otaUploadHandler(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);
|
2023-12-31 08:53:39 +00:00
|
|
|
void restAPIHandler(AsyncWebServerRequest *request);
|
2023-12-29 18:23:33 +00:00
|
|
|
};
|