-
Notifications
You must be signed in to change notification settings - Fork 9
/
FSWebServer.h
80 lines (70 loc) · 2.2 KB
/
FSWebServer.h
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef _FSWEBSERVER_h_
#define _FSWEBSERVER_h_
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#ifdef ESP32
#include <WiFi.h>
#include <AsyncTCP.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESP8266mDNS.h>
#endif
#include <WiFiClient.h>
#include <ESPAsyncWebServer.h>
#include <SPIFFS.h>
#include <Ticker.h>
#include <ArduinoOTA.h>
#include <ArduinoJson.h>
#define CONNECTION_LED -1 // Connection LED pin (Built in). -1 to disable
#define AP_ENABLE_BUTTON 5 // Button pin to enable AP during startup for configuration. -1 to disable
typedef struct {
String ssid;
String password;
IPAddress ip;
IPAddress netmask;
IPAddress gateway;
IPAddress dns;
bool dhcp;
String ntpServerName;
long updateNTPTimeEvery;
long timezone;
bool daylight;
String deviceName;
} strConfig;
typedef struct {
String APssid = "ESP"; // ChipID is appended to this name
String APpassword = "12345678";
bool APenable = false; // AP disabled by default
} strApConfig;
typedef struct {
bool auth;
String wwwUsername;
String wwwPassword;
} strHTTPAuth;
class FSWebServer : public AsyncWebServer {
public:
FSWebServer(uint16_t port);
void begin(FS* fs);
void handle();
protected:
FS* _fs;
void onHttpRelinquish(AsyncWebServerRequest *request);
void onHttpList(AsyncWebServerRequest *request);
bool onHttpNotFound(AsyncWebServerRequest *request);
void onHttpDelete(AsyncWebServerRequest *request);
void onHttpDownload(AsyncWebServerRequest *request);
bool handleFileRead(String path, AsyncWebServerRequest *request);
bool handleFileReadSD(String path, AsyncWebServerRequest *request);
void onHttpFileUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);
void onHttpWifiConnect(AsyncWebServerRequest *request);
void onHttpWifiScan(AsyncWebServerRequest * request);
void onHttpWifiStatus(AsyncWebServerRequest *request);
void onHttpWifiAP(AsyncWebServerRequest *request);
void onHttpWifiList(AsyncWebServerRequest *request);
};
extern FSWebServer server;
#endif // _FSWEBSERVER_h_