-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathESPMegaWebServer.hpp
60 lines (59 loc) · 2.13 KB
/
ESPMegaWebServer.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once
#include <FS.h>
#include <ESPAsyncWebServer.h>
#include <ESPMegaIoT.hpp>
#include <Update.h>
#include <FRAM.h>
#include <ArduinoJson.h>
#include <AsyncJson.h>
#include <all_html.h>
#include <ESPMegaCommon.hpp>
/**
* @brief Provides a web server for ESPMegaPRO
*
* 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.
*
* This class use FRAM address 301-400
*/
class ESPMegaWebServer
{
public:
ESPMegaWebServer(uint16_t port, ESPMegaIoT *iot);
~ESPMegaWebServer();
void begin();
void loop();
void resetCredentials();
char* getWebUsername();
char* getWebPassword();
void setWebUsername(const char* username);
void setWebPassword(const char* password);
void bindFRAM(FRAM *fram);
void loadCredentialsFromFRAM();
void saveCredentialsToFRAM();
AsyncWebServer* getServer();
bool checkAuthentication(AsyncWebServerRequest *request);
// Endpoints Handlers
void dashboardHandler(AsyncWebServerRequest *request);
void configHandler(AsyncWebServerRequest *request);
AsyncCallbackJsonWebHandler *saveConfigHandler;
void saveConfigJSONHandler(AsyncWebServerRequest *request, JsonVariant &json);
void getConfigHandler(AsyncWebServerRequest *request);
void getDeviceInfoHandler(AsyncWebServerRequest *request);
void otaRequestHandler(AsyncWebServerRequest *request);
void otaUploadHandler(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);
void restAPIHandler(AsyncWebServerRequest *request);
void rebootHandler(AsyncWebServerRequest *request);
private:
// FRAM
FRAM *fram;
// Credentials
char webUsername[32];
char webPassword[32];
// Web Server
AsyncWebServer *server;
uint16_t port;
// ESPMegaIoT
ESPMegaIoT *iot;
};