forked from r-downing/PersWiFiManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PersWiFiManager.h
83 lines (55 loc) · 1.54 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
DebugUtils.h - Simple debugging utilities.
*/
#ifndef DEBUGUTILS_H
#define DEBUGUTILS_H
#define DEBUGX
#ifdef DEBUGX
#define DEBUG_PRINT(...) Serial.print(__VA_ARGS__)
#define DEBUG_PRINTLN(...) Serial.println(__VA_ARGS__)
#else
#define DEBUG_PRINT(...)
#define DEBUG_PRINTLN(...)
#endif
#endif
#ifndef PERSWIFIMANAGER_H
#define PERSWIFIMANAGER_H
#ifdef ESP8266
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#define WEBSERVER ESP8266WebServer
#define WIFI ESP8266WiFi
#else
#include <WiFi.h>
#include <WebServer.h>
#define WEBSERVER WebServer
#define WIFI WiFi
#endif
#include <DNSServer.h>
#ifndef WIFI_CONNECT_TIMEOUT
#define WIFI_CONNECT_TIMEOUT 30
#endif
class PersWiFiManager {
public:
typedef std::function<void(void)> WiFiChangeHandlerFunction;
PersWiFiManager(WEBSERVER& s, DNSServer& d);
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 setConnectNonBlock(bool b);
void handleWiFi();
void startApMode();
void onConnect(WiFiChangeHandlerFunction fn);
void onAp(WiFiChangeHandlerFunction fn);
private:
WEBSERVER * _server;
DNSServer * _dnsServer;
String _apSsid, _apPass;
bool _connectNonBlock;
unsigned long _connectStartTime;
WiFiChangeHandlerFunction _connectHandler;
WiFiChangeHandlerFunction _apHandler;
};//class
#endif