forked from r-downing/PersWiFiManager
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPersWiFiManager.h
67 lines (44 loc) · 1.61 KB
/
PersWiFiManager.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
#ifndef PERSWIFIMANAGER_H
#define PERSWIFIMANAGER_H
#include <FS.h>
#include <ESP8266WiFi.h>
#include <Hash.h>
#include <ESPAsyncTCP.h> //https://github.com/me-no-dev/ESPAsyncTCP
#include <ESPAsyncWebServer.h> //https://github.com/me-no-dev/ESPAsyncWebServer
#include <ESPAsyncDNSServer.h> //https://github.com/devyte/ESPAsyncDNSServer
// //https://github.com/me-no-dev/ESPAsyncUDP
#include <SPIFFSEditor.h>
#include <Arduino.h>
#include <Ticker.h>
//#define WIFI_HTM_PROGMEM
#define WIFI_HTM_GZ_PROGMEM
#define WIFI_CONNECT_TIMEOUT 30
class PersWiFiManager
{
public:
typedef std::function<void(void)> WiFiChangeHandlerFunction;
PersWiFiManager(AsyncWebServer &s, AsyncDNSServer &d, const fs::FS& fs = SPIFFS);
bool attemptConnection(const String &ssid = "", const String &pass = "");
void setupWiFiHandlers();
bool begin(const String &ssid = "", const String &pass = "");
String getApSsid();
void setApCredentials(const String &apSsid, const String &apPass = "");
void setFSCredentials(const String &http_user = "admin", const String &http_pass = "password");
void setConnectNonBlock(bool b);
void handleWiFi();
void startApMode();
void onConnect(WiFiChangeHandlerFunction fn);
void onAp(WiFiChangeHandlerFunction fn);
private:
Ticker _tkWiFiH;
fs::FS _fs;
AsyncWebServer *_aserver;
AsyncDNSServer *_adnsServer;
String _apSsid, _apPass;
String _fsUser = "admin", _fsPass = "password";
bool _connectNonBlock;
unsigned long _connectStartTime;
WiFiChangeHandlerFunction _connectHandler;
WiFiChangeHandlerFunction _apHandler;
}; //class
#endif